美文网首页
java.lang.IllegalStateException:

java.lang.IllegalStateException:

作者: 那远远的云端 | 来源:发表于2022-06-15 10:26 被阅读0次

    在ViewPager中使用RecyclerView,或者快速滑动时,报了如下非必现错误

        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7297)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
        at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
        at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
        at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
        at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
        at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8056)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
    

    是由于RecyclerView的Prefetch导致,关闭即可

    mLayoutManager.setItemPrefetchEnabled(false)
    

    相关文章

      网友评论

          本文标题:java.lang.IllegalStateException:

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