Switching To A Specific Fragment Gives Strange Java.lang.nullpointerexception
Here is the problem i am currently facing. I have switched from Eclipse with ADT plugin to Android Studio recently and an error i never encountered on Eclipse appeared with Android
Solution 1:
just check whether getItem()
was returning null
for a Fragment
. if so set a default Fragment
!
Solution 2:
I managed to solve the problem by overrinding the onDestroy method in my map fragment.
@Overridepublic void onDestroyView() {
super.onDestroyView();
if (this.mapFrag != null
&& getFragmentManager().findFragmentById(
this.mapFrag.getId()) != null) {
getFragmentManager().beginTransaction().remove(this.mapFrag)
.commit();
this.mapFrag = null;
}
}
Solution 3:
I found another decision, try to use Fragments extending android.support.v4.app.Fragment
instead of android.app.Fragment
and use the android.app.FragmentTransaction
instead of android.support.v4.app.FragmentTransaction
I found a solution in this post:
Trying to remove fragment from view gives me NullPointerException on mNextAnim
Post a Comment for "Switching To A Specific Fragment Gives Strange Java.lang.nullpointerexception"