首页 > 解决方案 > 我正在运行我在 recyclerview 上的项目,滚动列表时出现错误

问题描述

我正在运行我的项目,recyclerview我在滚动列表时遇到错误。

当我向下滚动列表时,出现错误recycelrview并且我的应用程序关闭。

请参阅以下错误:

2019-03-25 22:40:45.464 746-801/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
2019-03-25 22:40:45.467 746-801/? E/ANDR-PERF-REQUEST: Failed to set timer
2019-03-25 22:40:45.922 29813-29813/com.example.narayanstore E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.narayanstore, PID: 29813
    java.lang.IndexOutOfBoundsException: Index: 50, Size: 50
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.example.narayanstore.RecyclerViewAdapter.onBindViewHolder(RecyclerViewAdapter.java:47)

标签: androidandroid-recyclerview

解决方案


通常

IndexOutOfBoundException

如果您尝试访问当前不在适配器中的数据,则会发生这种情况。

所以需要通过调用下面的方法来检查adapter中是否有数据变化。

notifyDataSetChanged()


推荐阅读