Android Firestore HashMap无法强制转换为Object

时间:2019-01-18 22:21:25

标签: android google-cloud-firestore

我尝试从Firebase获取数据并将其存储在ArrayList<Object>中。为此,我创建了此方法:

private void getWholeListObject(int i, SellerObject soa) {
    String userid = FirebaseAuth.getInstance().getCurrentUser().getUid();
    DocumentReference docRef = db.collection("Users").document(userid);



 // Get the document, forcing the SDK to use the offline cache
    docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            if (task.isSuccessful()) {
                // Document found in the offline cache
                DocumentSnapshot document = task.getResult();

                ArrayList<ShoppingListObject>shoppingLists = new ArrayList<>();
                shoppingLists = (ArrayList<ShoppingListObject>) document.get("shoppingLists");
                Log.i("asdf", "addNewDataToList: "+shoppingLists.get(i).getProducts());
               addNewDataToList(i, shoppingLists, soa);
            } else {

            }
        }
    });

}

错误发生在日志上。

这是我的Object班:

public class ShoppingListObject {
    String listname;
    ArrayList<String> products;

    public ShoppingListObject() {
    }

    public ShoppingListObject(String listname, ArrayList<String> products) {
        this.listname = listname;
        this.products = products;
    }

    public String getListname() {
        return listname;
    }

    public void setListname(String listname) {
        this.listname = listname;
    }

    public ArrayList<String> getProducts() {
        return products;
    }

    public void setProducts(ArrayList<String> products) {
        this.products = products;
    }
}

请找到我的Firestore结构的附件:

Database structure

0 个答案:

没有答案