android.support.v4.app.Fragment.mFragmentManager' on a null object reference -
i have follow lines of code using create navigationview load fragments , android application. getting error: android.support.v4.app.fragment.mfragmentmanager' on null object reference. created fragments , navigationview works.
public void selectdraweritem(menuitem menuitem){ fragment fragment = null; class fragmentclass = null; switch(menuitem.getitemid()){ case r.id.nav_show_all_events_activity: fragmentclass = alleventsfragment.class; break; case r.id.nav_whats_hot_today_activity: fragmentclass = whatshotfragment.class; break; } try { fragment = (fragment) fragmentclass.newinstance(); } catch (exception e) { e.printstacktrace(); } fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction().replace(r.id.flcontent, fragment).commit(); menuitem.setchecked(true); settitle(menuitem.gettitle()); mdrawer.closedrawers(); }
are sure have 2 menuitems in menu ? if there more, end null
fragment. add 'default' case switch statement:
switch(menuitem.getitemid()){ case r.id.nav_show_all_events_activity: fragmentclass = alleventsfragment.class; break; case r.id.nav_whats_hot_today_activity: fragmentclass = whatshotfragment.class; break; default: return; }
that should ensure fragment not null.
Comments
Post a Comment