首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >尝试检查数组条目时,不断收到"IndexOutOfBoundsException: Index: 0,Size: 0“

尝试检查数组条目时,不断收到"IndexOutOfBoundsException: Index: 0,Size: 0“
EN

Stack Overflow用户
提问于 2019-05-21 02:59:26
回答 1查看 15关注 0票数 0

我在menuItemArrayList中提供产品,当用户将他们选择的产品放在购物车中时,它们将被添加到selectionItemArrayList中。下面是我的代码,它检查购物车中是否已经存在该产品。如果是这样,那么只更新数量。

我一直在摆弄代码,但我一直收到这个错误

代码语言:javascript
复制
    IndexOutOfBoundsException: Index: 0, Size: 0

代码只是从回收器视图的onBindHolder中摘录的一段onClickListener:

代码语言:javascript
复制
int position = getAdapterPosition();

for (int j = 0; j <= selectionItemArrayList.size(); j++) {
if (menuItemArrayList.get(position).getMenuItemName().equals(selectionItemArrayList.get(j).selectionName)) { // Loop through selection array to see if item exists in array
selectionItemArrayList.get(j).selectionQuantity += 1; // if it does exist then only update the quantity by 1
} else {
// Get the item name, price and add 1 to the quantity
String menuItemName = menuItemArrayList.get(position).getMenuItemName();
 String menuItemPrice = menuItemArrayList.get(position).getMenuItemPrice();
SelectionItem selectionItems = new SelectionItem(menuItemName, menuItemPrice, 1);
selectionItemArrayList.add(selectionItems);
}
}

你知道我做错了什么吗?在将主数组中的产品名称与购物车数组中的产品名称进行比较的行上抛出异常。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56226685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档