Reputation: 31
I need to retrieve data from the children of the child node post_Category
in my Firebase db.
My tree structure looks like this:
I have tried this block of code in my Android Studio:
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
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