Why I get Null Pointer Exception in Android -


i facing issue of nullpointerexception. in app have 2 classes mainactivity , test. creating object main of mainactivity inside test class. when call display method of mainactivity inside test class main.display(); nullpointerexception. please check sample code below , recommend me changes doing wrong.

public class mainactivity extends activity {       public void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);          requestwindowfeature(window.feature_no_title);         setrequestedorientation(activityinfo.screen_orientation_portrait); // fixed         getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on); // orientation          setcontentview(r.layout.training_ten_position);          test test = new test(10);      }       public  mainactivity()  {         super();     }     public void display() {      }       }    public class test {         .         .         .         mainactivity main;          public test(int duration) {             // initializing data member             main = new mainactivity();         }          public void delay() {             .             .             .             main.display();         } 

do this

do nor create instance of mainactivity class.

public class mainactivity extends activity{   //make function static     public static void display(){     //do code      // whatever variables or views want use in method make them static   }  }  public class test extend activity{    //how call display function    mainactivity.display();  } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -