所以我试图让购物清单应用程序运行的代码的下面部分,但是我收到一个导致应用程序崩溃的错误。
代码:
public void setProduct(Context context, View shoppingListViewFragment, String userEmail, String userName, ListModel shoppingListModel, ItemModel productModel) {
String listID = shoppingListModel.getListID();
String listName = shoppingListModel.getListName();
String itemID = productModel.getItemID();
String itemName = productModel.getItemName();
Boolean currentList = productModel.getCurrentList();
productNameContainer.setText(itemName);
FirebaseFirestore dbRef = FirebaseFirestore.getInstance();
DocumentReference itemIdRef = dbRef.collection("products").document(listID)
.collection("shoppingListProducts").document(itemID);
itemView.setOnClickListener(view -> {
Map<String, Object> map = new HashMap<>();
if (currentList) {
map.put("currentList", false);
} else {
map.put("currentList", true);
}
itemIdRef.update(map).addOnSuccessListener(aVoid -> {
if (currentList) {
dbRef.collection("shoppingLists").document(userEmail)
.collection("userShoppingLists").document(listID).get().addOnCompleteListener(task -> {
Map<String, Object> map1 = (Map<String, Object>) task.getResult().get("users");
String notificationMessage = userName + " has just bought " + itemName + " from " + listName + "'s list!";
}
}
});
}
});
});
当应用程序运行时,在第 61 行发生致命错误,该行位于 for 循环“for (Map.Entry entry : map1.entrySet())”
基本上,如果某个列表是由某人共享的,代码会尝试将数据发送到通知集合。但是,如果没有人与我共享特定的购物清单,那么我会收到上述错误。
我正在关注的视频教程是:https : //www.youtube.com/watch?v=6RzB4HXzQyA&list=PLn2n4GESV0AmXOWOam729bC47v0d0Ohee&index=16
请帮忙。:)
慕的地10843
相关分类