android - Null Pointer exception passing data from activity to Fragment -


i have url value in mainactivity page , need pass url value activity fragment. when click button i'm getting null exception on line of string url=getarguments().getstring("btn_url");

activity:

 fragment fragment=new about();                                      if (fragment != null) {       fragmenttransaction transaction = getfragmentmanager().begintransaction();        transaction.replace(r.id.frame_container, fragment, "tag_fragment");         transaction.addtobackstack(null);         transaction.commit();             bundle bundle=new bundle();           bundle.putstring("btn_url", url); fragobj=new about();      fragobj.setarguments(bundle);     } 

fragment:

string url=getarguments().getstring("btn_url"); 

you need commit after set fragments arguments. change code this:

about fragobj=new about();     bundle bundle=new bundle(); bundle.putstring("btn_url", url);         fragobj.setarguments(bundle); getfragmentmanager().begintransaction(); .replace(r.id.frame_container, fragobj, "tag_fragment"); .addtobackstack(null); .commit();  

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -