Firebase Table Field Structure Image attached for your reference
我想要什么?只是想获取所有字段数据(如城市,电话等)
我确定,我需要在下面的代码行中进行一些更改:
PaidUsers paidUsers = dataSnapshot.getValue(PaidUsers.class);
这是代码,我正在使用它检查是否存在与uPhone对应的数据(并且工作得很好,并使用已注册和未注册的电话号码进行了检查),发现实现正确
private void fetchAndPopulateData() {
databaseReference.orderByChild("uPhone").equalTo(uPhone).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
Toast.makeText(getActivity(), "Data Exists", Toast.LENGTH_LONG).show();
// getting called
PaidUsers paidUsers = dataSnapshot.getValue(PaidUsers.class);
uPhone = paidUsers.getuPhone();
uCity = paidUsers.getuCity();
Snackbar.make(getView(), uPhone+"_"+uCity, Snackbar.LENGTH_LONG).show();
// getting null_null
} else {
Toast.makeText(getActivity(), "Data not exist", Toast.LENGTH_LONG).show();
Snackbar.make(getView(), "Create your Profile", Snackbar.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(getActivity(), "Cancelled Called", Toast.LENGTH_LONG).show();
}
});
}
但是无法从Firebase的PaidUsers表中检索数据,如下图所示,我正在尝试获取uPhone和uCity,但是却什么也没得到,请问为什么,我在哪里做错了?:
PaidUsers paidUsers = dataSnapshot.getValue(PaidUsers.class);
uPhone = paidUsers.getuPhone();
uCity = paidUsers.getuCity();
Snackbar.make(getView(), uPhone+"_"+uCity, Snackbar.LENGTH_LONG).show();
// getting null_null
我什么都没有得到,我想念什么吗?