Reputation: 4353
This is my JSON data structure in Firebase database:
familylist
|- 0
|--children
| |-- 0:"FGH"
| |-- 1:"HJU"
|-- code: "2222"
|-- family: "SWE"
|-- fatherName: "ABC"
|-- motherName: "XYZ"
|- 1
|--children
| |-- 0:"XXX"
| |-- 1:"YYY"
|-- code: "3333"
|-- family: "ABC"
|-- fatherName: "ERT"
|-- motherName: "XTS"
My code for retrieving Children
data from firebase-database:
DatabaseReference childrenKeyReference = FirebaseDatabase.getInstance().getReference().child("familylist").child("children").child(key);
Log.d(TAG, "children: " + childrenKeyReference);
childrenKeyReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String child = (String) dataSnapshot.getValue();
Log.d(TAG, "Child : " + child);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
This are the details from LogCat. Null values are getting displayed. I'm not able to figure out what's wrong. Please do correct me.
05-22 21:25:29.771 24743-24743/D/tag: children: https://bcm.firebaseio.com/familylist/children/0
05-22 21:25:29.774 24743-24743/D/tag: children: https://bcm.firebaseio.com/familylist/children/1
05-22 21:25:29.780 24743-24743/D/tag: Child : null
05-22 21:25:29.805 24743-24743/D/tag: Child : null
UPDATE
New Result after setting the order properly. I'm getting this:
05-22 20:52:36.091 8572-8572/D/tag: children: https://bcm.firebaseio.com/familylist/0/children/0
05-22 20:52:36.097 8572-8572/D/tag: children: https://bcm.firebaseio.com/familylist/1/children/1
05-22 20:52:36.136 8572-8572/D/tag: Child : FGH
05-22 20:52:36.137 8572-8572/D/tag: Child : YYY
Upvotes: 2
Views: 38
Reputation: 19339
You may have switched the nodes access order by accident ;)
You are currently doing this:
...child("familylist").child("children").child(key);
but maybe you should be doing:
...child("familylist").child(key).child("children");
since, according to your datamodel, familylist clearly doesn't have a children child node.
Upvotes: 2