java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is

开发中发现app内wishlist页面中心愿单商品,两个及以上时,同时取消关注,刷新列表会导致页面Crash。log如下:

08-24 16:09:28.138 14091 14091 E AndroidRuntime: Process: com.cider, PID: 14091
08-24 16:09:28.138 14091 14091 E AndroidRuntime: java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true com.cider.widget.LoadMoreRecycleView{d65fece VFED..... ......ID 13,0-707,1183 #7f09024c app:id/rvProductList}, adapter:com.cider.widget.LoadMoreRecycleView$WrapAdapter@96471ef, layout:androidx.recyclerview.widget.StaggeredGridLayoutManager@85584fc, context:com.cider.ui.activity.main.MainActivity@d3aac0d
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at androidx.recyclerview.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:6433)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at androidx.recyclerview.widget.RecyclerView$Recycler.quickRecycleScrapView(RecyclerView.java:6554)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at androidx.recyclerview.widget.RecyclerView$LayoutManager.removeAndRecycleScrapInt(RecyclerView.java:9249)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:4207)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3862)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at com.scwang.smartrefresh.layout.SmartRefreshLayout.onLayout(SmartRefreshLayout.java:617)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at com.cider.widget.NoPreloadViewPager.onLayout(NoPreloadViewPager.java:911)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at com.cider.widget.swipebackhelper.SwipeBackLayout.onLayout(SwipeBackLayout.java:278)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at com.android.internal.policy.DecorView.onLayout(DecorView.java:757)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.View.layout(View.java:20699)
08-24 16:09:28.138 14091 14091 E AndroidRuntime:   at android.view.ViewGroup.layout(ViewGroup.java:6198)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2865)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2392)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1527)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7394)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1036)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.Choreographer.doCallbacks(Choreographer.java:832)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.Choreographer.doFrame(Choreographer.java:767)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1022)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.os.Handler.handleCallback(Handler.java:873)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.os.Looper.loop(Looper.java:201)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at android.app.ActivityThread.main(ActivityThread.java:6810)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at java.lang.reflect.Method.invoke(Native Method)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
08-24 16:09:28.139 14091 14091 E AndroidRuntime:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)w

问题分析:Recyclerview更新数据时报crash

解决方案:在清空list后及时通知adapter更新下数据,即调用adapter的notifyDataSetChanged方法。之后的逻辑获取到数据list后再notifyDataSetChanged,即可正常展示数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值