0

I have been creating mobile application using Android and Firebase, I can't get data from firebase, the problem is in the line Survey survey = ds.getValue(Survey.class);, it work only when I delete attributes options and timestamp, Here is my code:

    private FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
private DatabaseReference mRootReference=firebaseDatabase.getReference();
private DatabaseReference mSurveysReference=mRootReference.child("surveys");


    mSurveysReference.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            for (DataSnapshot ds:dataSnapshot.getChildren()){
                Survey survey = ds.getValue(Survey.class);
                surveys.add(survey);
            }
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }
    });

enter image description here

    public class Survey {
    public boolean acceptAnonymousVotes;
    public boolean enabled;
    public String id;
    public String image;
    public Option[] options  ;
    public  boolean resultPublic;
    public Timestamp timeStamp;
    public  String title;
    public int totalComments;
    public int totalViews;
    public int totalVotes;
    public  String type;
    public String userId;
public Survey() {
}
}

public class Option {
   public int id ;
   public String title ;
}
naruto
  • 511
  • 1
  • 6
  • 11
  • What is the error? Have you checked related questions? like this one https://stackoverflow.com/questions/38462259/how-to-retrieve-the-data-firebase-3-0-database?rq=1 – Ravi Chandra May 29 '17 at 08:48

1 Answers1

0

According to https://firebase.google.com/docs/database/android/read-and-write , you need a default constructor that is required for calls to DataSnapshot.getValue(XY.class)

Also use List<Option> instead of Options[] for options.

Prexx
  • 2,959
  • 5
  • 31
  • 48