Reputation: 245
i have a fragmentactivity which calls other fragment by :
FragmentView1 f = (FragmentView1) this.getSupportFragmentManager()
.findFragmentByTag(getFragmentTag(0));
and my getFragmentTag() function is :
private String getFragmentTag(int pos){
return "android:switcher:"+R.id.viewpager+":"+pos; //fragmentpageradapter auto generated tag
}
not the problem is whenever i call f.somemethod , i get a nullpointerexception .
i tried with
Log.w("HELLO1",""+ f.getTag());
it return nullpointerexception .
Upvotes: 1
Views: 975
Reputation: 3022
findFragmentByTag() is returning null because it is not finding a fragment with the specified tag as per the docs. Ensure you are setting the fragment's tag in your layout or programatically at transaction time.
Refer to this question for more information on this.
Upvotes: 1