FragmentStatePagerAdapter with ChildFragmentManager – FragmentManagerImpl.getFragment results in NullPointerException

I would need to see more code in order to know where to apply this … but I had a similar situation as you did… I solved the ChildFragmentManager issue the same way, and got the same NullPointerException, as you have.

I did manage to solve it… I’ll try to describe my solution, as with the code you supplied I am unsure as to where to apply the “fix” … It really is a fix … it’s not an elegant way to solve this! It did however helped me, and I don’t need to restore states once I navigate away on the view Pager, so no downside for me.

I have multiple Fragments, that implement the static bit of code and the onDetach (on https://code.google.com/p/android/issues/detail?id=42601#c10), each fragment has a pager, and onCreateView I attach an adapter that extends FragmentStatePagerAdapter.

on those adapters I have overridden the restoreState method to do nothing

    @Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
    //do nothing here! no call to super.restoreState(arg0, arg1);
}

Again, this is not the best way… but it did solve my problem.

Best of luck!

Leave a Comment