Nullpointerexception On Onsaveinstancestate With Androidfragments
I am receiving a NullPointerException when I LEAVE a FragmentActivity and go to a ListActivity. I actually start to see the list before I get the Force Close. But the LogCat refe
Solution 1:
It looks like this is a known bug in the Android Support Library. Fortunately, it's been patched.
To fix the bug:
- Use the SDK Manager to update to the latest version of the support library
- Replace the
android-support-v4.jar
file in your application'slibs/
folder with the new version that you just downloaded
Solution 2:
Try this:
publicvoidonSaveInstanceState(Bundle savedInstanceState) {
if (savedInstanceState != null)
{
super.onSaveInstanceState(savedInstanceState);
}
}
Solution 3:
If you just want a quick workaround, add this to your Fragment code:
@OverridepublicvoidonSaveInstanceState(Bundle outState) {
// Workaround to avoid NPE from support library bug:setUserVisibleHint(false);
super.onSaveInstanceState(outState);
}
The setUserVisibleHint
property is indeed just a hint for optimization and shouldn't cause you any trouble, see Android reference documentation.
Of course, updating the Support library as answered by theisenp might be more desirable in the long run.
Solution 4:
I think you have used this style AppTheme.NoActionBar
in manifest file and in java class ,you are using actionbar that's why it cause crashes.
Can you show me your manifest file and style.xml
Post a Comment for "Nullpointerexception On Onsaveinstancestate With Androidfragments"