【问题标题】:Firestore recyclerview adapter generating out of bounds exceptionFirestore recyclerview 适配器生成越界异常
【发布时间】:2021-04-07 20:16:35
【问题描述】:

我有一个带有水平 Firestore recyclerview 和 textView 的活动,我想使用 recyclerview 中的第二个 event_name 项设置 textView

nameSwitcher.setText(options.getSnapshots().get(1).getEvent_name());

回收站视图正在工作,但 textView 正在生成 `

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)

【问题讨论】:

  • 请编辑您的问题和代码以从数据库中获取数据。还请添加您的数据库结构作为屏幕截图。

标签: android firebase google-cloud-firestore android-recyclerview


【解决方案1】:

您的列表为空。此检查将防止您的应用崩溃:

if (options.getSnapshots().size() >= 1) {
    nameSwitcher.setText(options.getSnapshots().get(1).getEvent_name());
}

【讨论】:

  • 它不是空的,在另一种方法中它在断点String evetName = options.getSnapshots().get(pos).getEvent_name(); option FirestoreRecyclerOptions@13220 pos: 3int pos = layoutManger.getActiveCardPosition(); 中工作
  • 我看不到您的完整代码,但异常清楚地表明您的列表中没有 2 个元素。
猜你喜欢
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-07
  • 2013-11-28
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多