I'm trying to retrieve the updated User from the dataSnapshot of the Firebase Database:
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User atualizedUser = dataSnapshot.getValue(User.class);
fName.setText(atualizedUser.getFirstName());
lName.setText(atualizedUser.getLastName());
profilePhoto.setProfileId(atualizedUser.getProfileId());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
But I get this error below:
com.google.firebase.database.DatabaseException: Class bqs.bomqueso.Model.User is missing a constructor with no arguments
at com.google.android.gms.internal.zzbtg$zza.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg$zza.zzaH(Unknown Source)
at com.google.android.gms.internal.zzbtg.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at bqs.bomqueso.Activities.MainActivity$3.onDataChange(MainActivity.java:92)
at com.google.android.gms.internal.zzbpx.zza(Unknown Source)
at com.google.android.gms.internal.zzbqx.zzZS(Unknown Source)
at com.google.android.gms.internal.zzbra$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Here my User class (this is not a subclass, I created it in a separate file):
public class User {
private String firstName;
private String lastName;
private String profileId;
public User() { }
public User(String fName, String lName, String id) {
this.firstName = fName;
this.lastName = lName;
this.profileId = id;
}
public String getProfileId() {
return profileId;
}
public void setProfileId(String id) {
this.profileId = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lName) {
this.lastName = lName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String fName) {
this.firstName = fName;
}
}
I find similar questions here, but I hadn't found a solution for my problem, I hope you guys can help me, Thank you in advance!