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

问题: This question already has an answer here: Class android.location.Location does not define a no-argument constructor 1 answer I am trying to fetch t...

问题:

This question already has an answer here:

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

  • 发表于 2019-02-19 01:02
  • 阅读 ( 912 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除