Skip to content Skip to sidebar Skip to footer

Childeventlistener Throws Nullpointerexception

I have a node in firebase database that I want to retrieve and put it in a spinner I made array list then looped through data snapshot but still give nullPointerException I stored

Solution 1:

You're attaching a ChildEventListener on Purposes. That means that its callback methods (onChildAdded, onChildChanged, etc) are called with a DataSnapshot of a child node of Purposes.

In your onChildAdded you're looping over the child nodes of that snapshot, which means that ds is a snapshot of an individual property name.

To fix the problem, don't loop over the child nodes in your onChild* methods:

publicvoidonChildAdded(DataSnapshot dataSnapshot, String previousChildKey) {
    String name = dataSnapshot.getValue(Purpose.class).getName();
    textView.setText(name);
}

Post a Comment for "Childeventlistener Throws Nullpointerexception"