-2

我正常加载回收站,数据显示正确。但我需要在特定条件下重新创建我的活动。当我重新创建我的活动时,Recycler 视图会再次初始化并加载新的数据集。但这一次我遇到了崩溃。以下是日志。任何帮助将非常感激.. !!!

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: start < 0 || end > len. start=-1, end=11, len=11
       at java.util.Arrays.checkStartAndEnd(Arrays.java:1732)
       at java.util.Arrays.fill(Arrays.java:803)
       at android.support.v7.widget.StaggeredGridLayoutManager$LazySpanLookup.invalidateAfter(StaggeredGridLayoutManager.java:2652)
       at android.support.v7.widget.StaggeredGridLayoutManager.handleUpdate(StaggeredGridLayoutManager.java:1496)
       at android.support.v7.widget.StaggeredGridLayoutManager.onItemsUpdated(StaggeredGridLayoutManager.java:1472)
       at android.support.v7.widget.RecyclerView$6.dispatchUpdate(RecyclerView.java:781)
       at android.support.v7.widget.RecyclerView$6.onDispatchFirstPass(RecyclerView.java:769)
       at android.support.v7.widget.AdapterHelper.dispatchFirstPassAndUpdateViewHolders(AdapterHelper.java:316)
       at android.support.v7.widget.AdapterHelper.dispatchAndUpdateViewHolders(AdapterHelper.java:302)
       at android.support.v7.widget.AdapterHelper.applyUpdate(AdapterHelper.java:222)
       at android.support.v7.widget.AdapterHelper.preProcess(AdapterHelper.java:106)
       at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1492)
       at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:151)
       at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:305)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
       at android.view.Choreographer.doCallbacks(Choreographer.java:670)
       at android.view.Choreographer.doFrame(Choreographer.java:603)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5417)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
4

2 回答 2

0

当您尝试重新创建您的activity时,RecyclerView仍在尝试显示view itemsComputingLayout

RecyclerView 处于锁定状态,任何更新适配器内容的尝试都会导致异常

解决方案

  • 您应该推迟recreate activity使用处理程序。
  • RecyclerView.isComputingLayout()在触发更改之前,检查应该返回 false。

更多详情查看我的回答

于 2017-11-14T12:12:39.353 回答
0

就我而言,我试图通知ItemChanged(Default_pos),其中Default_pos 是-1,它不存在。

因此我得到了 ArrayIndexOutOfBound。

于 2017-03-04T09:08:21.220 回答