我正在开发一个带有 ActionbarSherlock 和 Fragments 的应用程序(不确定是否相关)。
我的 MainActivity onPause() 应用程序崩溃了,我不知道为什么......
这是发生这种情况时的 LogCat 错误:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to pause activity {com.example.myapp/com.example.myapp.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2354)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291)
at android.app.ActivityThread.access$1700(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
at com.example.myapp.MainActivity.onSaveInstanceState(MainActivity.java:80)
at android.app.Activity.performSaveInstanceState(Activity.java:1037)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1181)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2336)
我的活动已经实现了默认的 onPause 方法(以及其他方法,应要求提供)
@Override
public void onPause() {
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
}
我认为这可能与 ActionbarSherlock 有关,因为错误消息是这样的。您可以投掷任何光,将不胜感激。我被困住了。