Nesting Fragments Inside A Viewpager Fragment Throws Indexoutofboundsexception
I am using a viewPager which contains 2 fragments. The first fragment contains nested fragments and the second one is an empty fragment. Inside the first fragment I am nesting 4 fr
Solution 1:
Figured out what was causing the error. Inside one of my fragments,I was calling
getActivity().getSupportFragmentManager().beginTransaction().remove(instance).commit();
which was using the fragment manager of the Activity instead of child fragment manager of the fragments'.
and hence this error:
java.lang.IndexOutOfBoundsException: Invalid index 3, size is2
where 3 was the index of the nested fragment and 2 was the size returned by the Activity's fragment manager.
Fixed it by using the fragment manager from the fragment instead of the Activity:
ThisFragment.this.getFragmentManager().beginTransaction().remove(instance).commit();
Post a Comment for "Nesting Fragments Inside A Viewpager Fragment Throws Indexoutofboundsexception"