1

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 .

user1304
  • 225
  • 2
  • 4
  • 11
  • 1
    My guess is your `getFragmentTag(0)` is not returning what you are expecting – BlackHatSamurai Jan 31 '13 at 21:15
  • no , it's returning the correct tag . i called 'getTag()' inside my FragmentView1 , and 'getFragmentTag(0)' in my fragmentActivity , and both returned the same result – user1304 Jan 31 '13 at 21:18

1 Answers1

1

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.

Community
  • 1
  • 1
Nick Rempel
  • 3,022
  • 2
  • 23
  • 31
  • i am using fragmentpageradapter , which automatically generates tags for the fragments , for which i am using getFragmentTag , which retrieves that auto generated tag of the fragment – user1304 Jan 31 '13 at 21:56