Tuesday, June 18, 2019

Android Error: int android.app.Fragment.mNextAnim

java.lang.NullPointerException: Attempt to write to field 'int android.app.Fragment.mNextAnim' on a null object reference


Solution 1: 

Check your code like:

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.hide(getFragmentManager().findFragmentById(R.id.map_info));
ft.commit();
Basically, you're calling remove(), hide(), etc., with a null value.

Solution 2:


Update 1

I changed map_info_layout to map_info and there's no change in the error I'm getting. I'd previously had map_info_layout defined as the id for the root FrameLayout of the MapInfoFragment's layout XML, so I think map_info_layout and map_info were pointing to the same thing.

Update 2: My solution

Turned out that I had MapInfoFragment extending android.support.v4.app.Fragment instead of android.app.Fragment and I were using the android.app.FragmentTransaction instead of android.support.v4.app.FragmentTransaction. Switched everything to android.app. since I'm not interested in older device compatibility. Thanks

Update 3: General solution

Stop trying to hide null objects

No comments:

Post a Comment