sudo sudo - 5 months ago 186
Android Question

Retrieve Firebase Data saved with push()

I have a Firebase database.When im saving data i used the

push()
to generate auto increment key.

now my db like this

recipe{
Categories{
-KJxZi0jbE1sY5cCFgqf{
name: "Sri Lankan"
}
}
}


When im retrieving data i got this error

W/ClassMapper: No setter/field for -KJxz53rLIc4rZPVjK48 found on class com.kosala.uyamu2.Data_Category


This my
Data_Category
Bean

public class Data_Category {

String name;

public Data_Category() {}
public Data_Category(String name) {
this.name = name;}
public String getName() {
return name;}
public void setName(String name) {
this.name = name;}}


This is where i retrieving data

mDatabase.child("recipe").child("Categories").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Data_Category data = dataSnapshot.getValue(Data_Category.class);
Log.d("name", data.getName());
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


Can any one help me here.Thanks.

Answer

use

 public void onDataChange(DataSnapshot dataSnapshot) {
       for (DataSnapshot data : dataSnapshot.getChildren()) 
                     Data_Category category = data.getValue(Data_Category.class);
       }
 }