RecyclerView问题:java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adap
###写在前面
在使用RecyclerView中出现了一个问题,如下图
###解决办法:
我们在使用RecycxlerView时,通常先回设置一个LayoutManager
我们的问题出现在LayoutManager的onLayoutChildren方法中,我们只要在onLayoutChildren中捕获这个异常即可,下面我以LinearLayoutManager为例。
先写一个类LinearLayoutManagerWrap继承LinearLayoutManager,然后重新onLayoutChildren方法即可,如下代码:
public class LinearLayoutManagerWrap extends LinearLayoutManager {public LinearLayoutManagerWrap(Context context) {super(context);}public LinearLayoutManagerWrap(Context context, int orientation, boolean reverseLayout) {super(context, orientation, reverseLayout);}public LinearLayoutManagerWrap(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr, defStyleRes);}@Overridepublic void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {// 在这里通过try来捕获这个异常即可try {super.onLayoutChildren(recycler, state);} catch (IndexOutOfBoundsException e) {e.printStackTrace();}}
}
然后把LinearLayoutManagerWrap设置RecyclerView即可
RecyclerView问题:java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adap相关推荐
- Recyclerview 出现 java.lang.IndexOutOfBoundsException: Inconsistency detected 异常
使用 RecyclerView 的时候报错 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view hold ...
- 解决IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter
解决IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter 最近项目已个要求,recyclervi ...
- Inconsistency detected Invalid view holder adapter position
RecyclerView在添加数据的时候发生了异常. java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view ...
- Inconsistency detected. Invalid view holder adapter positionVH
recycleview报错,是因为我的list引用了静态变量的list,直接=了,应该是list.addAll(静态变量list)
- java.lang.IndexOutOfBoundsExceptionInconsistency detected. Invalid view holder adapter position问题处理
工作中发现bugly上报了一个崩溃,日志如下: java.lang.IndexOutOfBoundsExceptionInconsistency detected. Invalid view hold ...
- IDEA报错Error:Module 'shop-common' production: java.lang.IndexOutOfBoundsException
问题描述: 本来项目是正常的,编译.运行.启动都是OK的,但是在一次电脑重启后,出现了以上这个问题:Error:Module 'shop-common' production: java.lang.I ...
- java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
哎 这类问题 本来都不打算记录的,但是自己写的时候还是犯了错误,一运行报错了 大致就是list 超出了 ,可能index size 值不一样( Index: 9, Size: 9, Index: 5, ...
- 5.java.lang.IndexOutOfBoundsException(数组下标越界异常)
5.java.lang.IndexOutOfBoundsException(数组下标越界异常) 参考文章: (1)5.java.lang.IndexOutOfBoundsException(数组下标越 ...
- ssh根据姓名查询的时候报错java.lang.IndexOutOfBoundsException: Remember that
错误如下: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! at org.hibe ...
最新文章
- java jersey使用总结_jersey使用指南
- 【每日DP】day 9、P1156 垃圾陷阱(神奇的背包,时间节点处理)难度⭐⭐⭐
- Redis最佳实践:业务层面和运维层面优化
- 直击2019WAIC丨李德毅:人工智能是脱离意识的工具,需要约束的是人类自己
- ActiveMQ BrokeUrl的配置和消息持久化配置
- STL源码学习----集合相关算法
- .val()数据乱码_【目标检测数据集】PASCAL VOC制作
- 【转】Web实现音频、视频通信
- 巧用XP的Hosts文件 防止误进恶意网站
- Redis 可视化工具 Redis Desktop Manager 和 treeNMS 的使用
- 《自己动手写操作系统》第二章——Bochs调试及相关仿真工具的使用方法
- redis进行对比时有对应的key却还是返回false
- [文档和源码分享]C++实现的基于α-β剪枝算法的井字棋游戏
- 四、DNS设置转发器
- 遥感测深方法综述(一)遥感测深方兴未艾
- TCP协议之RST与FIN
- android手机 恢复微信图片,微信图片过期了怎么恢复?记住这个操作,找回更清晰!...
- 生鲜蔬菜生产称重管理系统
- windows系统RNDIS驱动手动安装
- 一中OJ #1438 航线设计 | LIS 序列DP | 解题报告