java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is
2018-03-19 16:24
507 查看
前言
想必大家在项目中肯定或多或少会使用列表,像Android原生的Listview,Recyclerview,还有很多三方的开源框架:XRecyclerview,SmartRefreshLayout等等,github上面有很多,本小白才疏学浅直接找寻三方的框架来用,使用的是XRecyclerview,下面来说一下我在项目中遇到的问题。报错信息:
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:4878) at android.support.v7.widget.RecyclerView$Recycler.quickRecycleScrapView(RecyclerView.java:4951) at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleScrapInt(RecyclerView.java:7352) at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3101) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2917) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:724) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2069) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871) at android.view.Choreographer.doCallbacks(Choreographer.java:683) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)我的问题是在一个列表中原本存在一个待审核的数据,后台通过之后我下拉刷新之后,这条数据还存在,然后我发现在网络请求下拉刷新的时候没有进行列表清空,随后就在代码中添加了这样一句话:
CallServer.getRequestInstance().add(this, 0, params, new HttpListener<String>() { @Override public void onSucceed(int what, Response<String> response) { KLog.json(response.get());// dataList.clear();//添加的代码在这里 // adapter.notifyDataSetChanged(); try { JSONObject jsonObject = new JSONObject(response.get()); int code = jsonObject.getInt("code"); if (1 == code) { MySubmissionData submissionData = JSON.parseObject(jsonObject.toString(), MySubmissionData.class); List<MySubmissionData.DataBean> data = submissionData.getData(); adapter.refreshView(data); xrlv.refreshComplete(); } else { MyToast.showToast(MySubmissionAct.this, jsonObject.getString("message")); if ("暂无数据".equals(jsonObject.getString("message"))) { xrlv.refreshComplete(); } } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailed(int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) { } }, true, true);添加完这行代码就开始报上面那个错误,百度了一下说的还真不少,有说是因为recyclerview自带的条目动画和刷新不能共存,解决办法是把清空集合的操作放在刷新数据之后做,反正我是没有解决。还有一个是说是因为view没有被回收,数据清空之后,在从新添加数据的时候忘记通知界面去重新绘制了,所以报错,我是按照这个方法解决的。就是在添加的那行代码下边一行,把adapter.notifyDataSetChanged();这个注释打开就好了。
相关文章推荐
- java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is
- java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is
- java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is
- java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is
- java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false is
- IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:t
- java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled.
- RecyclerView 报Scrapped or attached views may not be recycled. as Scrap:false isAttached:true异常
- Scrapped or attached views may not be recycled. isScrap:false isAttached:true错误
- Scrapped or attached views may not be recycled. isScrap:false isAttached:true异常
- java.lang.IllegalArgumentException:Document base ……does not exist or is not a readable directory错误的解决方案
- Tomcat的异常 之 java.lang.IllegalArgumentException: Document base *** does not exist or is not a readable
- (转)Tomcat的异常 之 java.lang.IllegalArgumentException: Document base *** does not exist or is not a readable
- RecyclerView报错:Scrapped or attached views may not be recycled
- java.lang.IllegalArgumentException: D:\eclipse\.. does not exist or is not a readable directory解决方法
- Scrapped or attached views may not be recycled
- Tomcat的异常 之 java.lang.IllegalArgumentException: Document base xxx does not exist or is not a readab
- decorview that was originally added here or java.lang.IllegalArgumentException: View not attached to window manager
- Scrapped or attached views may not be recycled
- Error starting static Resources java.lang.IllegalArgumentException: Document base D:\Program Files\apache-tomcat-xxx\webapps\xxx does not exist or is not a readable directory