【发布时间】:2018-09-15 11:05:42
【问题描述】:
我正在尝试以 BusInformation.class 的形式从 firebase 实时数据库中获取数据。但是此时我的应用程序在设置快照的类类型时崩溃了:ds.getValue(BusInformation.class);
我收到以下错误:
com.google.firebase.database.DatabaseException: Class com.example.muzammil.bustracking.app_classes.BusInformation does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
at com.google.android.gms.internal.firebase_database.zzku.zza(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzkt.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
以下是 BuInformation.java 类的代码:
public class BusInformation {
private String id, username,phone;
private LatLng position;
private String destination;
public BusInformation(String id, String username, String phone, String destination,LatLng position) {
this.id = id;
this.username = username;
this.phone = phone;
this.position = position;
this.destination = destination;
}
}
在 Firebase 数据库中,数据完全以这种形式存在。
从firebase获取数据的代码:
public void getUpdatesFromFirebase(DataSnapshot dataSnapshot){
for(DataSnapshot ds : dataSnapshot.getChildren()){
if(ds.exists()) {
busInfo = ds.getValue(BusInformation.class); //App crashes at this point
}
}
}
任何人请告诉我代码有什么问题...
【问题讨论】:
标签: java android firebase firebase-realtime-database