I'm working on a simple app that can sign-in/sign-up.
Everything works normally except when I try to get data from the "Users" path on Realtime Database, I always get null for UID even though I already pushed my data and this is not a too complex part and I can get data normally with the exact same type others data?
This is the part where i define User object:
public class User {
String profile_picture_url , username , user_email, user_uid;
public User(){
}
public User(String profile_picture_url , String userUID , String username,String user_email)
{
this.profile_picture_url = profile_picture_url;
this.user_uid = userUID;
this.username = username;
this.user_email = user_email;
}
//GETTER
public String getProfile_picture_url() {
return profile_picture_url;
}
public String getUsername() {
return username;
}
public String getUser_EMail() {
return user_email;
}
public String getUserUID() {
return user_uid;
}
}
This is my json tree on Firebase:
This is the part where I retrieve the data:
private void readUserFromFB() {
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
Log.d("firebase_debug2",firebaseUser.getUid());
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
userList.clear();
for (DataSnapshot snapshot1 : snapshot.getChildren()) {
User user = snapshot1.getValue(User.class);
Log.d("firebase_debug2", " This is email " + user.getUser_EMail());
Log.d("firebase_debug2","This is uid " + user.getUserUID());
Log.d("firebase_debug2", "This is username " + user.getUsername());
userAdapter = new UserAdapter(getContext(), userList);
recyclerView.setAdapter(userAdapter);
}
}
@Override
public void onCancelled(@NonNull @NotNull DatabaseError error) {
}
});
}
Get this in logcat:
This is email tas@gmail.com
This is uid null
This is username tas
This is email wwqw@gmail.com
This is uid null
This is username wiiwi
Why do I get that annoying problem, hope somebody can help me find out because I tried for hours but can't figure out where I've missed.Thanks