我一直在使用Android和Firebase創建移動應用程序,我無法從Firebase獲取數據,問題出在線Survey survey = ds.getValue(Survey.class);
,它只在刪除屬性選項和時間戳時才起作用,這裏是我的代碼:如何從Firebase數據庫檢索數據
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) {
}
});
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 ;
}
什麼是錯誤?你有沒有檢查相關的問題?像這樣一個https://stackoverflow.com/questions/38462259/how-to-retrieve-the-data-firebase-3-0-database?rq=1 –