android - Change Fragment name in NavigationDrawer -


hello have implemented activity used navigation drawer.its work fine app crashing because of actionbar.it throw nullpointerexception

i called fragment follows

you can't call getactivity oncreateview, may return null, if activity isn't attached yet fragment.

activities , fragments have separate lifecycles, getactivity can null while fragment in process of preparation.

you can move code depends on getactivity fragment.onactivitycreated(bundle) callback. note called after oncreateview.

see more info here: https://developer.android.com/guide/components/fragments.html#coordinatingwithactivity

update: requested, here's fixed code - split of oncreateview method onactivitycreated

@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     person = new person();     str = person.getfragment();     view = inflater.inflate(r.layout.fragment_product_list, container, false);     return view; }  @override public void onactivitycreated(bundle savedinstancestate) {     cd = new connectiondetector(getactivity());     parent = (appcompatactivity) getactivity();     if (getarguments() != null) {         title = getarguments().getstring("title");         if (title != null) {             parent.getsupportactionbar().settitle(title);         }     } } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -