When reading from this firebase database it always returns null instead of the value I need.
I have tried pulling it in the form of a String with the String.class but its still null.
What I need to pull from the data base is just the int dose and the pName variable in this case would be dfdf

final FirebaseDatabase aDatabase = FirebaseDatabase.getInstance();
final DatabaseReference mDatabase = aDatabase.getReference();
DatabaseReference myRef = aDatabase.getReference(pName).child("dose");
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
Integer Value = dataSnapshot.getValue(Integer.class);
String peter = Integer.toString(Value);
count.setText(peter);
}
@Override
public void onCancelled(DatabaseError error) {
count.setText("E");
}
});
Try changing -
DatabaseReference myRef = aDatabase.getReference(pName).child("dose");
to -
DatabaseReference myRef = mDatabase.child(pName).child("dose");
you should be running on mDatabase not aDatabase and get the child not reference
And change the listener to
addListenerForSingleValueEvent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With