For some reason when receiving data from fire base real time database, no matter which account I log into or whatever the database will always return "points" as 0, even when the value store in the database is not zero. The Uid is definitely correct as I checked that.I do not understand why and I have been trying to fix this problem for a while now.The code has worked in different activities and nothing has changed.
databaseUsers =FirebaseDatabase.getInstance().getReference("Users");
final FirebaseAuth firebaseAuth;
firebaseAuth = FirebaseAuth.getInstance();
user = firebaseAuth.getCurrentUser();
databaseUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
points = dataSnapshot.child(user.getUid()).child("points").getValue(int.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
//Getting Total Points from Firebase Database
databaseUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
totalpoints = dataSnapshot.child(user.getUid()).child("totalpoints").getValue(int.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});