可能重复:
onSaveInstanceState 上的 NullPointerException 与 AndroidFragments
当我在某些设备上调用 super.onSaveInstanceState 时,我在 android.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1542) 处得到 NullPointerException,而另一些则可以。
public void onSaveInstanceState(Bundle savedInstanceState) {
//...
super.onSaveInstanceState(savedInstanceState);
}
Nexus 平板电脑上的 Android 4.1 可以正常工作,而三星的 Android 4.0 则不行。这里有什么问题,我该如何解决?取消注释 onSaveInstanceState 有效,但我认为这是不正确的,它使我的应用程序在其他地方表现不正确。
谢谢马文
编辑添加的堆栈跟踪
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1542)
at android.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1572)
at android.app.Activity.onSaveInstanceState(Activity.java:1164)
at com.MApp.MActivity.onSaveInstanceState(MActivity.java:1111)
at android.app.Activity.performSaveInstanceState(Activity.java:1113)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1188)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3337)
at android.app.ActivityThread.access$700(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1163)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)