When I debug this code, in databaseUser dataSnapshot has the values from User in database, but in the object user1
, did not add, it\'s all null. And I don\'t un
I once faced that problem, and the solution was quite amazing.
You should add setters in your User
class.
Try it, and you won't regret it.
When you execute a query against the Firebase Database, there will potentially be multiple results. By attaching a ValueListener
you get those results in one snapshot, so the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result.
Your code fails to take this "list of results" into account. It's easy to fix by looping over the DataSnapshot.getChildren()
:
databaseUser.orderByChild("userEmail").equalTo(user.getEmail()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
User user1 = userSnapshot.getValue(User.class);