【发布时间】:2016-03-13 06:51:44
【问题描述】:
firebase=new Firebase("https://flickering-inferno-4404.firebaseio.com/User/awosome");
firebase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String temp=dataSnapshot.getValue().toString();
GenericTypeIndicator<List<User>> t=new GenericTypeIndicator<List<User>>(){};
List<User> userList=dataSnapshot.getValue(t);
if (userList!=null){
userList.get(0).getBirthYear();
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
而用户模型是
public class User {
private int birthYear;
private String fullName;
public User() {}
public User(String fullName, int birthYear) {
this.fullName = fullName;
this.birthYear = birthYear;
}
public long getBirthYear() {
return birthYear;
}
public String getFullName() {
return fullName;
}
}
但是在List<User> userList=dataSnapshot.getValue(t); 在线我遇到了类似的错误
致命异常:主要 进程:com.chhota.firebasepractice,PID:8233 com.firebase.client.FirebaseException:无法反弹输入 在 com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:210) 在 com.chhota.firebasepractice.MainActivity$1.onDataChange(MainActivity.java:40) 在 com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:56) 在 com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45) 在 com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38) 在 android.os.Handler.handleCallback(Handler.java:733)
【问题讨论】:
标签: java android firebase firebase-realtime-database