android - Boolean show null reference exception -


i tried many time creating setting page mean setting button handle on , off in application class extends application show me boolean reference null exception. following manifest.

             <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme"     android:name=".applicationclass">     <activity android:name=".splashscr">         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> 

and java class.

public class applicationclass extends application { myservice.reciver  rec; private context context;  public boolean getsoundfx_state() {     return soundfx_state; }  public void setsoundfx_state(boolean soundfx_state) {     this.soundfx_state = soundfx_state; }  boolean soundfx_state;  @override public void oncreate() { super.oncreate();   regster();      pndng();      setsoundfx_state(true); }  protected   void regster() {     try {     rec=new myservice().new reciver();     if(soundfx_state==true) {          registerreceiver(                 rec, new intentfilter(                         "android.intent.action.phone_state"));         toast.maketext(getbasecontext(), "your call can disconect   automatically", toast.length_short)                 .show();       } 

and setting.java class.

    public class setting extends activity {      myservice.reciver  rec;     private checkbox c1,c2;     protected  applicationclass app;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.setting);         app=(applicationclass)getapplication();         c1=(checkbox)findviewbyid(r.id.checkbox);         c2=(checkbox)findviewbyid(r.id.checkbox2);         rec=new myservice().new reciver();         if(app.getsoundfx_state())         {             c1.setchecked(true);         }         else {             c1.setchecked(false);         }          c1.setoncheckedchangelistener(new checkbox.oncheckedchangelistener() {             @override             public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {                  if(ischecked) {                      toast.maketext(getbasecontext(), "c1", toast.length_long).show();                     app.setsoundfx_state(true);                  }                 else {                     app.setsoundfx_state(false);                     toast.maketext(getbasecontext(),"off",toast.length_short).show();                  }             }         });         c2.setoncheckedchangelistener(new checkbox.oncheckedchangelistener() {             @override             public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {                 toast.maketext(getbasecontext(),"c2",toast.length_long).show();             }         });         {          };      }        public  void  chkboxclicked(view view)     {      } } 

1) change

boolean soundfx_state;  

to

boolean soundfx_state; 

2)

@override public void oncreate() {     super.oncreate();     setsoundfx_state(true);      regster();      pndng();   } 

hope make sense.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -