I am trying to retrieve data from my firebase database and print a statement in a text field but I keep getting null values. I'm using the userid
to try and get to the child node that I want. My textfield keeps saying "Welcome null logged-in as null" My Firebase Database
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
final String uid;
FirebaseUser user;
user = FirebaseAuth.getInstance().getCurrentUser();
uid = user.getUid();
DatabaseReference reference =
FirebaseDatabase.getInstance().getReference("User");
reference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
fName = dataSnapshot.child(uid).child("fName").getValue(String.class);
role = dataSnapshot.child(uid).child("role").getValue(String.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
welcomeText = (TextView) findViewById(R.id.welcomeText);
welcomeText.setText("Welcome " + fName + "! You are logged-in as " + role);