我正在尝试从Android中的Firebase实时数据库中获取FirebaseLocationData对象。
根据Docs,该类不应具有我已经做过的参数构造函数, public FirebaseLocationData() {}但仍显示错误
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);
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; }
}
您正在尝试编写一个android.location.Location对象, 并且 该类没有公共的,无参数的构造函数。许多Android库类无法满足Firebase的要求,因此您必须编写自己的序列化/反序列化才能与数据库交换必要的信息。
android.location.Location