I am using firebase database for my app and I saved my users in it.
This is my UserInformation
class:
public class UserInformation {
private String email1;
private String Password1;
public HashMap<String, Boolean> SayingsLevels=new HashMap<>();
public HashMap<String, Boolean> songs=new HashMap<>();
public UserInformation (String email, String Password){
this.email1=email;
this.Password1=Password;
SayingsLevels.put("1", false);
SayingsLevels.put("2", false);
SayingsLevels.put("3", false);
songs.put("1", false);
songs.put("2", false);
songs.put("3", false);
}
And I saved it with this code on my main activity:
firebaseUser=FirebaseAuth.getInstance().getCurrentUser();
UserInformation user=new UserInformation(email1,password1);
String id=firebaseUser.getUid();
mDatabaseReference.child("user").child(id).setValue(user);
Now, I want the get the hashmap data that was stored in my database. I used the following code:
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mDatabase = FirebaseDatabase.getInstance().getReference();
firebaseuser=FirebaseAuth.getInstance().getCurrentUser();
id=firebaseuser.getUid();
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren() ){
UserInformation user= dataSnapshot1.child("user").child(id).getValue(UserInformation.class);
}
but on variable user I'm getting all the time null
, what I did wrong?
Thanks for help!