2017-05-29 6 views
0

Ich habe mobile Anwendung mit Android und Firebase erstellt, kann ich keine Daten von Firebase, das Problem ist in der Zeile Survey survey = ds.getValue(Survey.class);, funktioniert es nur, wenn ich Attribute Optionen und Zeitstempel, hier löschen mein Code:So rufen Sie Daten aus Firebase-Datenbank

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 ; 
} 
+0

Was ist der Fehler? Haben Sie verwandte Fragen überprüft? wie diese https://stackoverflow.com/questions/38462259/how-to-retrieve-the-data-firebase-3-0-database?rq=1 –

Antwort

0

nach https://firebase.google.com/docs/database/android/read-and-write, benötigen Sie einen Standard-Konstruktor, der für Anrufe in DataSnapshot.getValue (XY.class)

erforderlich ist

Verwenden Sie auch List<Option> anstelle von Options[] für Optionen.

+0

Ich tat, aber immer noch nicht arbeiten – naruto

+0

Für beide Klassen? Was ist der Fehler? – Prexx

+0

funktioniert es nur, wenn ich Attribute Optionen und Zeitstempel lösche, was kann ich tun? – naruto