gpt4 book ai didi

java.lang.ClassCastException : java. lang.Boolean 无法转换为 java.util.Map

转载 作者:行者123 更新时间:2023-11-29 23:25:36 25 4
gpt4 key购买 nike

我在这一行中收到错误:“Map map = (Map) dataSnapshot.getValue();”

     private void getAssignedCustomer(){
String driverId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverId);
assignedCustomerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){

Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();

if(map.get("customerRideId") != null){
customerId = map.get("customerRideId").toString();
getAssignedCustomerPickupLocation();
}
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

如何摆脱这个错误???

最佳答案

引自 Firebase 文档:

getValue() returns the data contained in this snapshot as native types. The possible types returned are:

Boolean

String

Long

Double

Map

List

This list is recursive; the possible types for Object in the above list is given by the same list. These types correspond to the types available in JSON.

dataSnapshot.getValue() 返回的值似乎是Boolean,它当然不能分配给Map<String, Object> .

确保您使用的是来自 dataSnapshot 的正确数据

关于java.lang.ClassCastException : java. lang.Boolean 无法转换为 java.util.Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53633734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com