android - 我正在运行我在 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)
解决方案
通常
IndexOutOfBoundException
如果您尝试访问当前不在适配器中的数据,则会发生这种情况。
所以需要通过调用下面的方法来检查adapter中是否有数据变化。
notifyDataSetChanged()
推荐阅读
- android-studio - 未找到 ID 为“androidx.navigation.safeargs”的插件
- apache-camel - Unable to load class org.eclipse.jetty.server.Connector error while establishing secured soap server using apache CXF
- java - optaplanner BendableLongScore with two softScores
- java - 使用 DirectByteBuffer 的 Kafka 生产者
- c# - 为什么 Linq Prepend() 不适用于 List
? - angular - 带有嵌套路由的 Angular routerLinkActive
- multithreading - 由于 OutOfMemoryError 导致 DataFrame 广播失败时,Apache Spark 驱动程序挂起
- mysql - 在 HANA DB 上使用 UNION SELECT 和过滤器时如何获得更好的性能
- python - 如何从熊猫数据框列广播文本字符串的子集
- visibility - A-frame:通过单击隐藏另一个系列后显示一系列元素