ListPreference中的ArrayIndexOutOfBoundsException

时间:2014-02-28 04:47:36

标签: android android-preferences

我在Play-Console中有一个奇怪的StackTrace - 我无法重现问题而且它不是直接源于我的代码。也许这里的某个人有一个关于如何处理这个问题的想法,而不仅仅是忽略它。虽然只发生了一次 - 但我真的很想知道那里发生了什么。

java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
    at android.preference.ListPreference.getEntry(ListPreference.java:203)
    at android.preference.ListPreference.getSummary(ListPreference.java:148)
    at android.preference.Preference.onBindView(Preference.java:522)
    at android.preference.Preference.getView(Preference.java:460)
    at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221)
    at android.widget.AbsListView.obtainView(AbsListView.java:2308)
    at android.widget.ListView.makeAndAddView(ListView.java:2030)
    at android.widget.ListView.fillDown(ListView.java:822)
    at android.widget.ListView.fillFromTop(ListView.java:883)
    at android.widget.ListView.layoutChildren(ListView.java:1848)
    at android.widget.AbsListView.onLayout(AbsListView.java:2136)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1652)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14177)
    at android.view.ViewGroup.layout(ViewGroup.java:4399)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2244)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2017)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1190)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4860)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:766)
    at android.view.Choreographer.doCallbacks(Choreographer.java:575)
    at android.view.Choreographer.doFrame(Choreographer.java:542)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:751)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:5751)
    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:1083)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
    at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:3)

我假设您正在使用PreferenceActivity或PreferenceFragment(Compat)

在您的首选项xml文件中定义 ListPreference 参数时似乎缺少一些东西, 我相信您的 android:entries android:entryValues 尺寸不匹配。

答案 1 :(得分:0)

每当您尝试访问哪个更大或没有在arraylist的边界(超出大小)时,都会发生java.lang.ArrayIndexOutOfBoundsException:错误。

因此,从显示java.lang.ArrayIndexOutOfBoundsException: length=3; index=3的错误中,有时会发生您尝试访问大于数组大小的值的错误。由于您的arraylist仅包含总共3条记录,因此您可能尝试访问3位置的索引。虽然数组从索引“0”开始计算其值,因此会有像0,1,2...这样的值,因此在这种情况下,它将无法获得索引“3”处的值不可用。

所以"java.lang.ArrayIndexOutOfBoundsException: length=3; index=3"。这意味着您请求的索引超出了数组的范围。换句话说,数组有一个长度(它的边界)。当它的长度为3(它是空的)并且你要求第3个元素时,数组会告诉你你请求的项目是不可用的,因为数组甚至不是3个元素长。