如果存在dataSnapshot,流程将继续执行if语句 但是我尝试了很多数据保存在firbase上 使用此代码dataSnapshot不存在
private void getAssignedCustomer(){
String driverId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverId).child("customerRideId");
assignedCustomerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.getValue() !=null){
cutomerId =dataSnapshot.getValue().toString();
getAssignedCustomerPickupLocation();
}else{
Toast.makeText(DriverMapActivity.this , "data snap not exist", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
答案 0 :(得分:-1)
由于这些原因,不存在常见原因datasnapshort。
1.child路径名与firebase json树路径名不匹配。
2。您的路径中不存在数据。
请更改此
if(dataSnapshot.getValue()!=null){
cutomerId =dataSnapshot.getValue().toString();
getAssignedCustomerPickupLocation();
}else{
Toast.makeText(DriverMapActivity.this , "data snap not exist", Toast.LENGTH_SHORT).show();
};
对此
if(dataSnapshot.exists()){
cutomerId =dataSnapshot.getValue(String.class);
getAssignedCustomerPickupLocation();
}else{
Toast.makeText(DriverMapActivity.this , "data snap not exist", Toast.LENGTH_SHORT).show();
};