我的应用程序出现以下异常。我相信当用户离开应用程序很长时间然后返回时会发生这种情况。我无法复制它,但它在我的崩溃日志中出现了很多。我不知道为什么会发生这种情况,因此非常感谢任何建议。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MyActivity}: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4974)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1
at java.util.ArrayList.get(ArrayList.java:306)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1764)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:198)
at com.myapp.MyActivity.onCreate(MyActivity.java:235)
at android.app.Activity.performCreate(Activity.java:4538)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
... 11 more
第 235 行如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // line 235
我的 onSaveInstanceState() 非常简单:
@Override
public void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
state.putInt("id1", id1);
state.putInt("id2", id2);
state.putInt("id3", id3);
state.putInt("id4", id4);
}