Firebase : Can't convert object of type java.lang.String to type com.example.g.Model.Cart

后端 未结 2 1219
难免孤独
难免孤独 2021-01-16 16:34

I had error that said

com.google.firebase.database.DatabaseException: Can\'t convert object of type java.lang.String to type com.example.g.Model.Cart

2条回答
  •  萌比男神i
    2021-01-16 17:09

    From your code it looks like you are iterating a layer too deep in your structure. Easy Fix: Replace

    for (DataSnapshot ds : dataSnapshot.getChildren()) {
        for (DataSnapshot cart : ds.getChildren()) {
             CartList.add(cart.getValue(Cart.class));
        }
    }
    

    with

    for (DataSnapshot cart : dataSnapshot.getChildren()) {
         CartList.add(cart.getValue(Cart.class));
    }
    

提交回复
热议问题