我正在尝试删除我的RecyclerView. 使用 livedata 和 diffutil 监视对列表的更改。只有在RecyclerView删除第一个项目(第 0 个索引)时才会发生崩溃。这可能看起来与其他相关问题相似。快速滚动等时不会出现此问题。仅在删除第 0 个位置的项目时才会出现。项目本身从数据库中删除。但应用程序崩溃。我尝试从RecyclerView课程中追溯错误:.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5923)
从 RecyclerView.java:
if (offsetPosition < 0 || offsetPosition >= mAdapter.getItemCount()) {
throw new IndexOutOfBoundsException("Inconsistency detected. Invalid item "
+ "position " + position + "(offset:" + offsetPosition + ")."
+ "state:" + mState.getItemCount());
}
Run Code Online (Sandbox Code Playgroud)
偏移位置小于 0 (-1)
完整的错误堆栈:
03-23 08:55:38.739 25087-25087/com.application.essentials E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.application.essentials, PID: 25087
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 0(offset:-1).state:3 android.support.v7.widget.RecyclerView{41df14f0 VFED.V.. ......ID …Run Code Online (Sandbox Code Playgroud)