android - Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference -


this question has answer here:

i'm using android studio. app stops when try , switch tabs , gives me error:

java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.class java.lang.object.getclass()' on null object reference        @ android.support.v4.app.backstackrecord.doaddop(backstackrecord.java:394)        @ android.support.v4.app.backstackrecord.add(backstackrecord.java:389)        @ android.support.v4.app.fragmentpageradapter.instantiateitem(fragmentpageradapter.java:103)        @ android.support.v4.view.viewpager.addnewitem(viewpager.java:1005)        @ android.support.v4.view.viewpager.populate(viewpager.java:1219)        @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:665)        @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:627)        @ android.support.v4.view.viewpager.setcurrentitem(viewpager.java:608)        @ android.support.design.widget.tablayout$viewpagerontabselectedlistener.ontabselected(tablayout.java:2169)        @ android.support.design.widget.tablayout.dispatchtabselected(tablayout.java:1164)        @ android.support.design.widget.tablayout.selecttab(tablayout.java:1157)        @ android.support.design.widget.tablayout.selecttab(tablayout.java:1127)        @ android.support.design.widget.tablayout$tab.select(tablayout.java:1426)        @ android.support.design.widget.tablayout$tabview.performclick(tablayout.java:1536)        @ android.view.view$performclick.run(view.java:21173)        @ android.os.handler.handlecallback(handler.java:739)        @ android.os.handler.dispatchmessage(handler.java:95)        @ android.os.looper.loop(looper.java:145)        @ android.app.activitythread.main(activitythread.java:6838)        @ java.lang.reflect.method.invoke(native method)        @ java.lang.reflect.method.invoke(method.java:372)        @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1404)        @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1199) 

my code stores of information on tabs , fragments

please me find error.

private sectionspageradapter msectionspageradapter;  private viewpager mviewpager;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.vault_screen);      toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      msectionspageradapter = new sectionspageradapter(getsupportfragmentmanager());       mviewpager = (viewpager) findviewbyid(r.id.container);     mviewpager.setadapter(msectionspageradapter);      tablayout tablayout = (tablayout) findviewbyid(r.id.tabs);     tablayout.setupwithviewpager(mviewpager);      floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab);     fab.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             snackbar.make(view, "replace own action", snackbar.length_long)                     .setaction("action", null).show();         }     });  }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_vault_screen, 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_settings) {         return true;     }      return super.onoptionsitemselected(item); } //deleted placeholderfragment class here  /**  * {@link fragmentpageradapter} returns fragment corresponding  * 1 of sections/tabs/pages.  */ public class sectionspageradapter extends fragmentpageradapter {      public sectionspageradapter(fragmentmanager fm) {         super(fm);     }      @override     public fragment getitem(int position) {          switch (position) {             case 0:                 tab1contacts tab1 = new tab1contacts();                 return tab1;             case 1:                 tab2chat tab2 = new tab2chat();                 return tab2;             case 3:                 tab3online tab3 = new tab3online();                 return tab3;             default:         return null;     }     }      @override     public int getcount() {         // show 3 total pages.         return 3;     }      @override     public charsequence getpagetitle(int position) {         switch (position) {             case 0:                 return "home";             case 1:                 return "private browser";             case 2:                 return "notes";         }         return null;     }  } 

i had same error because tried fragments tag or id. had fragments creating new objects, @ least if there none yet

 fragment fragment = new blankfragment(); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -