java - Caught a RuntimeException from the binder stub implementation when swap data in arrayadapter -


public class mainactivity extends appcompatactivity {       arraylist<string> list = new arraylist<>();       arrayadapter<string> adapter;       arraylist<string> data1 = new arraylist<>();       arraylist<string> data2 = new arraylist<>();  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      (int = 0 ; i< 10 ;i++){         data1.add(string.valueof(i));     }      (int = 20; < 30; i++){         data2.add(string.valueof(i));     }      spinner spinner = (spinner) findviewbyid(r.id.demo);     adapter = new arrayadapter<>(this,android.r.layout.simple_dropdown_item_1line,list);     spinner.setadapter(adapter); }  private void change(boolean which){     if (which){         list.clear();         list.addall(data1);      }else{         list.clear();         list.addall(data2);      }     adapter.notifydatasetchanged(); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_main, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_no) {         change(true);         return true;     }else if (id == r.id.action_ok){         change(false);         return true;     }      return super.onoptionsitemselected(item); }   } 

when swap data in spinner , there error :

08-25 11:51:59.630   29087-9866/me.aber.app.arrayapdapterdemo d/dalvikvm? gc_for_alloc freed 2055k, 52% free 7378k/15192k, paused 24ms, total 30ms 08-25 11:52:01.923   29087-9866/me.aber.app.arrayapdapterdemo w/binder? caught runtimeexception binder stub implementation.     java.lang.nullpointerexception @ android.view.windowmanagerglobal.dumpgfxinfo(windowmanagerglobal.java:437) @ android.app.activitythread$applicationthread.dumpgfxinfo(activitythread.java:1021) @ android.app.applicationthreadnative.ontransact(applicationthreadnative.java:550) @ android.os.binder.exectransact(binder.java:404) @ dalvik.system.nativestart.run(native method) 

this appears randomly click action.

i nullpointerexception , solve issues figuring out source of exception. compilers log summary isn't helpful. suggest putting log statements around if , else blocks. put log before , after calls clear method. if see log missing in android monitor means found source. can manipulate code accordingly.

i have experienced myself how tricky can adapters be. when call clear on adapter clears list adapter attached to. put check list null or empty before calling clear method.

when debug way , figure out actual cause, share us. question unique , never answered before.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -