我正在尝试从Firebase Realtime获取FirebaseLocationData对象 Android中的数据库。
根据Docs,该类应该没有我所做的参数构造函数
public FirebaseLocationData() {}
但它仍然显示错误
com.google.firebase.database.DatabaseException: Class android.location.Location does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
我应该如何制作 android.location.Location 类的无参数构造函数?
此行FirebaseLocationData fld = dataSnapshot.getValue(FirebaseLocationData.class);
码
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
Log.d(TAG, "onChildAdded:" + dataSnapshot.getKey());
FirebaseLocationData fld = dataSnapshot.getValue(FirebaseLocationData.class);
Toast.makeText(MainActivity.this, fld.getEmail()+" added", Toast.LENGTH_SHORT).show();
}
FirebaseLocationData类:
public class FirebaseLocationData {
String email;
Location location;
String time;
public FirebaseLocationData() {
}
public FirebaseLocationData(Location location, String email, String time) {
this.location = location;
this.email = email;
this.time = time;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
}
答案 0 :(得分:1)
您正在尝试编写Elements contentinstantiate = doc.select("span.mw-headline, h3 ~ a");
for (int i=0; i < contentinstantiate.size(); i++) {
System.out.println(contentinstantiate.get(i).text());
}
对象,并且 类没有公共的无参数构造函数。许多Android库类都不符合Firebase的要求,您必须编写自己的序列化/反序列化来与数据库交换必要的信息。
另见:Class android.location.Location does not define a no-argument constructor