我有一个购物应用程序,我需要保存一个对象列表,保存到 firestorm 工作正常,但是在获取数据后,它不断崩溃并抛出错误,如果有人可以提供帮助,提前谢谢你
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shoppingapp, PID: 2110
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.example.shoppingapp.models.CheckoutModel
Map<String,Object> paymentMap = new HashMap<>();
paymentMap.put("total",String.valueOf(itemsTotal));
paymentMap.put("items",list);
firebaseFirestore
.collection("Orders")
.document(uniqueID)
.set(paymentMap)
firebaseFirestore
.collection("Orders")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
for(DocumentSnapshot document : task.getResult()){
List<CheckoutModel> map = (List<CheckoutModel>) document.get("items");
String totalPrice = document.get("total").toString();
// TESTING BY GETTING PRODUCT ID
// it throws exception here
textView.setText(map.get(0).getProductID());
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
可以做两件事,
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句