Firebase “用户缺少没有参数的构造函数”溶液:
2022-09-01 23:58:00
我正在尝试从Firebase中的/User/树中检索我的用户详细信息。我有以下用户对象:
public class User {
private String name;
private String email;
private FirebaseUser firebaseUser;
private String lastOnline;
private LatLng latLng;
private ArrayList<SwapLocation> locations;
public User(){ }
public String getName(){
if(firebaseUser.getDisplayName() != null && !firebaseUser.getDisplayName().equals(""))
return firebaseUser.getDisplayName();
if(name != null && !name.equals(""))
return name;
return "";
}
public void setName(String name){
this.name = name;
}
public String getEmail(){
if(firebaseUser.getEmail() != null && firebaseUser.getEmail().equals(""))
return firebaseUser.getEmail();
if(email != null && email.equals(""))
return email;
return "";
}
public void setEmail(String email){
this.email = email;
}
public void setFirebaseUser(FirebaseUser firebaseUser){
this.firebaseUser = firebaseUser;
}
public FirebaseUser getFirebaseUser(){
return firebaseUser;
}
public void setLastOnline(String lastOnline){
this.lastOnline = lastOnline;
}
public String getLastOnline(){
if(lastOnline != null)
return lastOnline;
return "";
}
public void setLatLong(LatLng latlng){
this.latLng = latlng;
}
public LatLng getLatLong(){
return this.latLng;
}
public ArrayList<SwapLocation> getLocations(){
return locations;
}
public void setLocations(ArrayList<SwapLocation> locations){
this.locations = locations;
}
}
我正在尝试从 Firebase 中检索此对象。该对象在 dataSnapshot 中检索,尽管它在序列化到我的 User 对象时出现问题。
这就是我从Firebase检索对象的方式:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child(users_group).child(user.getUid());
ref.addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User this_user = dataSnapshot.getValue(User.class);
}
@Override
public void onCancelled(DatabaseError databaseError) { }
});
但是,当尝试执行“User this_user = dataSnapshot.getValue(User.class)”时,我收到一个错误,说“用户缺少一个没有参数的构造函数”
任何帮助都会很棒,谢谢