How to add no-argument constructor of inbuilt class for Firebase-database exception? [duplicate]

ε祈祈猫儿з 提交于 2019-12-31 06:35:41

问题


I am trying to fetch the FirebaseLocationData object from Firebase Realtime Database in Android.

According to Docs, the class should have no arguments constructor which i have done as public FirebaseLocationData() {} but it is still showing error

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.

How am i supposed to make a no-argument constructor of android.location.Location class?

Error is produced by this line FirebaseLocationData fld = dataSnapshot.getValue(FirebaseLocationData.class);

code:

 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 class:

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;
}

}


回答1:


You're trying to write a android.location.Location object and that class doesn't have a public, no-argument constructor. Many Android library classes will not meet the requirements from Firebase, and you'll have to write your own serialization/deserialization to exchange the necessary information with the database.

Also see: Class android.location.Location does not define a no-argument constructor



来源:https://stackoverflow.com/questions/50894716/how-to-add-no-argument-constructor-of-inbuilt-class-for-firebase-database-except

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!