今天使用RecyclerView时,上下两个RecyclerView,在实现下拉刷新时,报错:

java.lang.IndexOutOfBoundsException: Inconsistency detected.
  Invalid view holder adapter positionViewHolder{56798b2 position=2 id=-1, oldPos=2, pLpos:-1 scrap [attachedScrap] tmpDetached no parent}

在网上看到这个方法可以暂时性解决问题

其实也不是什么解决方法,只是把这个异常捕获了,不让他奔溃了,这个问题的终极解决方案还是得让google去修复。

1、创建一个类LinearLayoutManagerWrapper继承LinearLayoutManager,重写onLayoutChildren方法

  1. public class WrapContentLinearLayoutManager extends LinearLayoutManager {
  2. public WrapContentLinearLayoutManager(Context context) {
  3. super(context);
  4. }
  5. public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
  6. super(context, orientation, reverseLayout);
  7. }
  8. public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  9. super(context, attrs, defStyleAttr, defStyleRes);
  10. }
  11. @Override
  12. public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
  13. try {
  14. super.onLayoutChildren(recycler, state);
  15. } catch (IndexOutOfBoundsException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }

2、设置RecyclerView的布局管理为WrapContentLinearLayoutManager对象

  1. mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

RecycleView Bug:java.lang.IndexOutOfBoundsException: Inconsistency detected.的更多相关文章

  1. RecycleView错误: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder

    1.错误 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positi ...

  2. 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30

    RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...

  3. Recyclerview 出现 java.lang.IndexOutOfBoundsException: Inconsistency detected 异常

    使用 RecyclerView 的时候报错 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view hold ...

  4. RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案(转)

    转自:RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解 ...

  5. Android中RecyclerView出现java.lang.IndexOutOfBoundsException

    在RecyclerView更细数据时出现java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder ...

  6. java.lang.IndexOutOfBoundsException: setSpan (35 ... 35) ends beyond length 28

    /************************************************************************************* * java.lang.I ...

  7. 日志异常:java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.impl.StaticLoggerBinder

    今天启动开发的项目,碰到了一个日志上的bug:java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.impl.Sta ...

  8. sparksql读取hive数据报错:java.lang.RuntimeException: serious problem

    问题: Caused by: java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: ...

  9. maven发布到tomcat报错: Publishing failed Could not publish to the server. java.lang.IndexOutOfBoundsException

    eclipse中将maven项目发布到tomcat报错时: Publishing failed Could not publish to the server. java.lang.IndexOutO ...

随机推荐

  1. node 第一天

    在开发的过程中,几乎不可能一次性就能写出毫无破绽的程序,断点调试代码是一个普遍的需求. 作为前端开发工程师,以往我们开发的JavaScript程序都运行在浏览器端,利用Chrome提供的开发者工具就可 ...

  2. 发生dev_queue_xmit的时候,全部都是从ip_finish_output中来的吗

    也就是说啊,内核中的收发包的路径,很可能是经理driver_recv --> tcp -->driver_send这样一个过程,是个很长的路径呢...... 从dev_queue_xmit ...

  3. js 关键字 in 判断 一个属性或方法是否属于一个对象

    判断对象是否为数组/对象的元素/属性: 格式:(变量 in 对象)......注意,,, 当“对象”为数组时,“变量”指的是数组的“索引”: 当“对象”为对象是,“变量”指的是对象的“属性”. 判断 ...

  4. HDU 3879 Base Station(最大权闭合子图)

    将第i个用户和他需要的基站连边,转化成求二分图的最大权闭合子图. 答案=正权点之和-最小割. # include <cstdio> # include <cstring> # ...

  5. CentOS 文件及目录等

    1.在linux中一切皆是文件,只是类型不同,通过ls -l看到的一个字母表示文件的类型 -:普通文件. d:目录文件. l:链接文件. b:块设备文件. c:字符设备文件. p:管道文件. 2.文件 ...

  6. 【POJ2728】Desert King(分数规划)

    [POJ2728]Desert King(分数规划) 题面 vjudge 翻译: 有\(n\)个点,每个点有一个坐标和高度 两点之间的费用是高度之差的绝对值 两点之间的距离就是欧几里得距离 求一棵生成 ...

  7. BZOJ4137 & 洛谷4585:[FJOI2015]火星商店问题

    https://www.lydsy.com/JudgeOnline/problem.php?id=4137 https://www.luogu.org/problemnew/show/P4585 火星 ...

  8. BZOJ2002:[HNOI2010]弹飞绵羊——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2002 https://www.luogu.org/problemnew/show/P3203 某天, ...

  9. [zhuan]动态链接库中的.symtab和.dynsym

    http://blog.csdn.net/beyond702/article/details/50979340 原文如下: shared library (.so) "Program Lib ...

  10. STM32 - 软件设置单片机重启

    __set_FAULTMASK();//关闭总中断 NVIC_SystemReset();//请求单片机重启 执行NVIC_SystemReset()函数不允许被打断,所以关总中断