Skip to content Skip to sidebar Skip to footer

Datasnapshot Has The Object But Getvalue() Will Return Null

So I'm struggling with this issue for about three hours now. I have this user class public class User { private String user_id; private String userName; private long phoneNumber;

Solution 1:

You need to iterate over dataSnapshot.getChildren(...for example

for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
                    User user = childSnapshot.getValue(User.class);
                 }

Solution 2:

I had this same problem, turns out it was happening because the class (in your case User.class) doesnt have setter methods for the required variables

Solution 3:

It can also return null if the read permission is set to false in firebase real-time database rules. Setting it to true would return the values.

Post a Comment for "Datasnapshot Has The Object But Getvalue() Will Return Null"