1

I want to retrieve saved data in firebase real-time database, but the result is always null.

Below is the code.

    try{
        mDatabase = FirebaseDatabase.getInstance().getReference();
        myBal.setText("0");
        mDatabase.child("users").child(mUserId).child("claim").addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String amount  = dataSnapshot.child("satoshi").getValue(String.class);
                myBal.setText("satoshi: "+amount);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

Below is my database structure...

enter image description here

Thanks in advance!

1 Answer 1

3

The problem is you're not actually reaching the "satoshi" node.

The ValueEventListener on the "claim" node returns a DataSnapshot representing the "claim" node. There is no "satoshi" child on the "claim" node, the only child is "-Kbvm.....".

You would need to either have the "-Kbvm....." key already and use that to properly follow the path to "satoshi" or else use a ChildEventListener on the "claim" node to get the children of "claim" rather than "claim" itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.