ListView android的java.lang.IndexOutOfBoundsException

时间:2014-11-24 14:47:45

标签: android listview android-listview

当我设置页脚视图时,我在ListView面临一些奇怪的问题。我添加了页脚链接以在到达ListView中的结束元素时加载更多内容,并在加载时将其删除。 ListView支持CursorAdapter

直到Kitkat没有任何问题它运行良好,但是当我在加载更多元素时更改片段时更新了android L,它会跟随以下跟踪崩溃:

11-15 17:20:19.532: E/AndroidRuntime(11784): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
11-15 17:20:19.532: E/AndroidRuntime(11784):  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at java.util.ArrayList.get(ArrayList.java:308)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.widget.ListView.dispatchDraw(ListView.java:3307)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:15117)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.widget.AbsListView.draw(AbsListView.java:4083)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14048)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14043)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:15117)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14048)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14043)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14043)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1057)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:15117)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14048)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14043)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.draw(View.java:14838)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3210)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14043)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14008)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14008)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14008)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.updateDisplayListIfDirty(View.java:14008)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.View.getDisplayList(View.java:14071)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
11-15 17:20:19.532: E/AndroidRuntime(11784):  at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)

当我删除页脚时它工作正常。我正在使用AsyncTask加载更多内容并在表格中插入值,并使用notifyChange通知更改。

我不知道自己做错了什么。如果有人告诉我这个问题会很好。

2 个答案:

答案 0 :(得分:4)

我有完全相同的问题/相同的堆栈跟踪。就我而言,我在片段中使用支持v4库,在添加片段时使用setCustomAnimations。当我没有设置popExit动画时,问题就停止了。也许这也是你的情况。
我没有找到任何其他解决方法,我认为它只是支持库中的错误。有用的主题 Remove with delayAnimation between fragments

答案 1 :(得分:-1)

我通过以下方式解决了这个问题:

W/System.err: java.io.FileNotFoundException: /system/hash: open failed: EROFS (Read-only file system)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
W/System.err:     at java.io.PrintWriter.<init>(PrintWriter.java:168)
W/System.err:     at net.lockoil.updaterutmhelper.UpdaterService$Task$1.onResponse(UpdaterService.java:99)
W/System.err:     at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err:     at android.os.Looper.loop(Looper.java:148)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5461)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
W/System.err:     at libcore.io.Posix.open(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:438)

然后:

arrayAdapter.notifyDataSetChanged()