java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true
at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5736)
at android.support.v7.widget.RecyclerView$Recycler.recycleView(RecyclerView.java:5680)
at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:289)
at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:336)
at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:349)
at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:356)
at android.support.v7.widget.GapWorker.run(GapWorker.java:387)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:740)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:630)
我们通过log信息查看源码就能明白是什么地方报错了
at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5736)
进入源码查看recycleViewHolderInternal方法
发现是这里报的错。然后Scrapped or attached views may not be recycled. isScrap:false isAttached:true
isAttached:true 表示你的holder.itemView.getParent 不等null 。
所以这时候你就需要去查找你的代码中哪个地方创建了ViewHolder ,在ViewHolder中设置ItemView时是不是设置了parent
我这边是设置了parent, 然后设置了 true,
解决办法就是 把true 设为false 。或者 把parent设置null。
以后碰到什么异常多看源码。你能从源码中解决很多问题。
网友评论