• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How can I add properties to the button from different pages?

darkcoder

Lurker
May 20, 2020
1
0
Hello guys,

How can I add properties to the button from different pages/class ?

I need to add a property from the otherpage.java page to the button on the mainactivity.java page.But not working. (additional screenshots available)

I shouldn't open the MainActivity page (dont use Intent)

1.Page:Otherpage.java
Java:
        holder.btnSepeteEkle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                MainActivity main = new MainActivity();
                main.test();
}


2.Page: MainActivity.java
Java:
    public void test(){
       Button buton = findViewById(R.id.buttondeneme);
       buton.setText("BUTTON TEST");
    }

Error Detail:
Code:
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication9, PID: 5087
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
        at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:159)
        at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
 

Attachments

  • sss.jpg
    sss.jpg
    379.3 KB · Views: 157

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones