美文网首页Android代码踩坑池
RecyclerView报错:Invalid view hold

RecyclerView报错:Invalid view hold

作者: 祥龙翔天 | 来源:发表于2018-03-09 18:41 被阅读0次

    不停的remove Item出现的错误

    在IPackageDataObserver.Stub的onRemoveCompleted回调中去remove Recycler中的Item,当不停的remove时,出现如下错误

    E AndroidRuntime: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{8f220e0 position=22 id=-1, oldPos=-1, pLpos:-1 scrap [attachedScrap] update tmpDetached no parent}
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5041)
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5172)
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5153)
    E AndroidRuntime:   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2061)
    E AndroidRuntime:   at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:562)
    E AndroidRuntime:   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408)
    E AndroidRuntime:   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580)
    E AndroidRuntime:   at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3374)
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3183)
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1593)
    E AndroidRuntime:   at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:323)
    E AndroidRuntime:   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
    E AndroidRuntime:   at android.view.Choreographer.doCallbacks(Choreographer.java:723)
    E AndroidRuntime:   at android.view.Choreographer.doFrame(Choreographer.java:655)
    E AndroidRuntime:   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
    E AndroidRuntime:   at android.os.Handler.handleCallback(Handler.java:789)
    E AndroidRuntime:   at android.os.Handler.dispatchMessage(Handler.java:98)
    E AndroidRuntime:   at android.os.Looper.loop(Looper.java:164)
    E AndroidRuntime:   at android.app.ActivityThread.main(ActivityThread.java:6565)
    E AndroidRuntime:   at java.lang.reflect.Method.invoke(Native Method)
    E AndroidRuntime:   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    E AndroidRuntime:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
    

    后来发现,IPackageDataObserver.Stub回调是在子线程,在子线程中去remove recycler中的item就会出上面的错误。奇怪的是提示的错误却是这般,记录在案,敬RecyclerView

    相关文章

      网友评论

        本文标题:RecyclerView报错:Invalid view hold

        本文链接:https://www.haomeiwen.com/subject/qftmfftx.html