android – 保存状态异常

前端之家收集整理的这篇文章主要介绍了android – 保存状态异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序出现以下异常.我相信当用户离开应用程序很长一段时间然后返回它时会发生这种情况.我无法复制它,但它在我的崩溃日志中出现了很多.我不知道为什么会这样,所以任何建议都非常感谢.
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);

}

解决方法

我遇到了同样的问题,我相信它是android的一个bug.看一下这个主题,寻找可能的解决方http://code.google.com/p/android/issues/detail?id=22404
原文链接:https://www.f2er.com/android/314490.html

猜你在找的Android相关文章