Android中RecyclerView出现Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
来源:互联网 发布:沃特沃德 知乎 编辑:程序博客网 时间:2024/06/14 09:43
出现的原因
RecyclerView使用的关键在于“动态”绑定了数据,通过LayoutManager来进行数据的相关界面展示。也就是说,如果我当前RecyclerView的数据
变化不当时会造成RecyclerView的错误。所以,在进行数据移除和数据增加时,务必要保证RVAdapter中的数据和移除的数据保持一致!
解决方法
自定义一个类继承LinearLayoutManager,重写下面这个方法,并且在里面捕捉这个异常.
@Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { try { super.onLayoutChildren(recycler, state); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } }
然后RecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
这种方法治标不治本,只能让程序不崩溃,根本问题还是没解决,不过还是先应急吧。
0 0
- Android中RecyclerView出现Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position 解决方案
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position …
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- 成功解决RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 的解决方案
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position的一种规避方式
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state
- 解决java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 1(offset:1)
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- Python数据分析
- 第七周项目1—建立顺序环形队列算法库
- DNS 原理入门
- JQuery输入框中输入内容改变事件
- LINUX设备驱动模型之class
- Android中RecyclerView出现Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- Linux下Python模式下【Tab】自动补全
- 3.npm
- 单链表反转(C++)
- Docker学习总结(16)——当当网Docker应用实践
- Fragment 通过构造函数传数据 出现崩溃Bug
- eclipse从数据库逆向生成Hibernate实体类
- 第七周-项目四 队列数组
- 个人总结