访问SharedPreferences时出现奇怪的IndexOutOfBoundsException

时间:2016-11-26 23:58:39

标签: android sharedpreferences

我今天收到的崩溃日志:

@IBAction func exit() {
    UIView.animate(withDuration: 0.6, animations: { [weak self] in
        let frame = self?.view.frame
        self?.view.frame = CGRect(x: 0, y: frame!.maxY, width: frame!.width, height: frame!.height)
    })
}

我的方法的代码(在DataManager类中):

Exception java.lang.RuntimeException:
Unable to start activity ComponentInfo{org.my.app/org.my.app.WorkoutActivity}: java.lang.IndexOutOfBoundsException: Invalid index 2, size is 0
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2343)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2395)
android.app.ActivityThread.access$600 (ActivityThread.java:162)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1364)
android.os.Handler.dispatchMessage (Handler.java:107)
android.os.Looper.loop (Looper.java:194)
android.app.ActivityThread.main (ActivityThread.java:5392)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:525)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:833)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:600)
dalvik.system.NativeStart.main (NativeStart.java)

Caused by java.lang.IndexOutOfBoundsException: Invalid index 2, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException (ArrayList.java:251)
java.util.ArrayList.get (ArrayList.java:304)
org.my.app.DataManager.isPreviousMarathonAvailable (DataManager.java)
org.my.app.WorkoutActivity.onCreate (WorkoutActivity.java)
android.app.Activity.performCreate (Activity.java:5122)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1084)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2307)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2395)
android.app.ActivityThread.access$600 (ActivityThread.java:162)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1364)
android.os.Handler.dispatchMessage (Handler.java:107)
android.os.Looper.loop (Looper.java:194)
android.app.ActivityThread.main (ActivityThread.java:5392)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:525)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:833)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:600)
dalvik.system.NativeStart.main (NativeStart.java)

我不明白如何在此代码中获取IndexOutOfBoundsException。这个堆栈跟踪意味着它比我的方法更深入?我搜索了这个问题(共享首选项和索引越界异常),得到这个link,但根本不了解情况。另外我知道这次崩溃的用户有Android 4.2.2 HTC Desire 210双卡。所以,问题是:这次崩溃发生的地方,这是我的错误代码还是一些Android内部错误?我现在没有同样的崩溃,只有一次设备崩溃。

0 个答案:

没有答案