【发布时间】:2018-04-15 14:21:42
【问题描述】:
我尝试从 Firebase 实时数据库中读取用户的数据,但它总是返回 null。这是我的代码:
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference();
ref.child("shop").child("Users").child(mAuth.getCurrentUser().getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Users user = dataSnapshot.getValue(Users.class);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("1abc", "Failed to read value.", error.toException());
}
});
这是用户类:
public class Users {
private String full_name;
private String UID;
private String email;
public Users(String newemail, String newUID, String newfull_name) {
// ...
this.email=newemail;
this.full_name=newfull_name;
this.UID=newUID;
}
public Users() {
// ...
}
}
谁能告诉我我哪里错了?提前致谢。
【问题讨论】:
-
你遇到了什么错误?
-
检查
mAuth.getCurrentUser().getUid()的值 -
@kdblue 没有错误,只是运行不正确
-
@Pavneet_Singh:这很正常 :(
-
@Dang Tam 接受我的回答,它会帮助别人!谢谢。
标签: android firebase firebase-realtime-database