转载请注明链接:https://blog.youkuaiyun.com/feather_wch/article/details/88294135
RecyclerView 出现的越界问题解决方案
java.lang.IndexOutOfBoundsException: Inconsistency detected. RecyclerView
版本:2019-03-07(12:30)
现象
1、RecyclerView刷新数据,虽然数据没有越界,但是报错java.lang.IndexOutOfBoundsException: Inconsistency detected.
代码:
mAdapter.notifyItemRangeChanged(0, mDataList.size());
报错:
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{904fae6 position=3 id=-1, oldPos=3, pLpos:-1 scrap [attachedScrap] tmpDetached no parent}
解决办法
使用notifyDataSetChanged()
更改代码为:
mAdapter.notifyDataSetChanged();
RecyclerView越界异常修复
针对RecyclerView在刷新数据时出现的java.lang.IndexOutOfBoundsException异常,本文详细分析了错误原因,并提供了使用notifyDataSetChanged()替代notifyItemRangeChanged()的有效解决方案。
2973

被折叠的 条评论
为什么被折叠?



