1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by darkcoder, May 20, 2020.

  1. darkcoder

    darkcoder Lurker
    Thread Starter

    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
    Code (Java):
    1.         holder.btnSepeteEkle.setOnClickListener(new View.OnClickListener() {
    2.             @Override
    3.             public void onClick(View view) {
    4.  
    5.                 MainActivity main = new MainActivity();
    6.                 main.test();
    7. }

    2.Page: MainActivity.java
    Code (Java):
    1.     public void test(){
    2.        Button buton = findViewById(R.id.buttondeneme);
    3.        buton.setText("BUTTON TEST");
    4.     }
    Error Detail:
    Code (Text):
    1. E/AndroidRuntime: FATAL EXCEPTION: main
    2.     Process: com.example.myapplication9, PID: 5087
    3.     java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
    4.         at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:159)
    5.         at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
    6.  
     

    Attached Files:

    • sss.jpg
      sss.jpg
      File size:
      379.3 KB
      Views:
      51



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...