Joko NdiOha
Joko NdiOha

Reputation: 31

How to Retrieve Value From Firebase Database Child Node?

I need to retrieve data from the children of the child node post_Category in my Firebase db.

My tree structure looks like this:

enter image description here

I have tried this block of code in my Android Studio:

enter image description here

But I keep getting a null pointer exception. How can I retrieve the value from each of the children of the post_Category node?

Upvotes: 1

Views: 1322

Answers (1)

John O'Reilly
John O'Reilly

Reputation: 10330

I suspect issue is that you need to update your code to something like following (assuming you have Category pojo mapped to the firebase post_Category data).

for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
    Category category = childSnapshot.getValue(Category.class);
}

Upvotes: 1

Related Questions