DatabaseReference is missing a constructor with no arguments

1,275 views
Skip to first unread message

Evans Attafuah

unread,
Jun 23, 2016, 2:52:20 AM6/23/16
to Firebase Google Group
I keep getting this error and I haven't found any relevant solution on the internet. Am using a custom model with firebase annotation. when I make updates to a field on firebase I fire a value change event and this error shows up. Has anybody encountered this same issue. Help Needed.

Best Regards,
Evans. 

Evans Attafuah

unread,
Jun 23, 2016, 3:09:40 AM6/23/16
to Firebase Google Group
here is my code

@IgnoreExtraProperties
public class Profile {

private String displayName;
private String statusMessage;
private DatabaseReference contacts;
private String thumbUrl;
private String imageUrl;
private String userId;
private String pushId;
private String theme;

public Profile() {
// Default constructor required for calls to DataSnapshot.getValue(Profile.class)
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getDisplayName() {
return displayName;
}

public void setDisplayName(String profileName) {
this.displayName = profileName;
}

public String getStatusMessage() {
return statusMessage;
}

public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}

public DatabaseReference getContacts() {
return contacts;
}

public void setContacts(DatabaseReference contacts) {
this.contacts = contacts;
}

public String getThumbUrl() {
return thumbUrl;
}

public void setThumbUrl(String thumbURL) {
this.thumbUrl = thumbURL;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public String getPushId() {
return pushId;
}

public void setPushId(String pushId) {
this.pushId = pushId;
}

public String getTheme() {
return theme;
}

public void setTheme(String theme) {
this.theme = theme;
}

@Exclude
public HashMap<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();

if (displayName != null) {
result.put(Config.KEY_DISPLAY_NAME, displayName);
}

if (statusMessage != null) {
result.put(Config.KEY_STATUS_MESSAGE, statusMessage);
}

if (thumbUrl != null) {
result.put(Config.KEY_THUMB_URL, thumbUrl);
}

if (imageUrl != null) {
result.put(Config.KEY_IMAGE_URL, imageUrl);
}

if (pushId != null) {
result.put(Config.KEY_PUSH_ID, pushId);
}

if (theme != null) {
result.put(Config.KEY_THEME, theme);
}

return result;
}

}

public static void getProfile(final String userId, final ProfileListener.onLoad onLoad) {

//create a profile reference
//use the single event listener to retrieve data
final DatabaseReference profileReference = FirebaseDatabase.getInstance().getReference().child(Config.REF_PROFILES).child(userId);
profileReference.addListenerForSingleValueEvent(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot profileSnapshot) {
// new Testable.Spec(userId).describe("change event").expect(profileSnapshot.getValue()).run();
if (profileSnapshot.exists()) {
Profile profile = profileSnapshot.getValue(Profile.class);
profile.setUserId(profileSnapshot.getKey());
// profile.setDisplayName(userContact.getDisplayName());
onLoad.load(profile);


}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

Michael Lehenbauer

unread,
Jun 27, 2016, 4:34:12 PM6/27/16
to Firebase Google Group
Hi Evans,

The problem is DatabaseReference can't be read/written to Firebase Database because it doesn't have a default no-argument constructor (see requirements for Java objects written to Firebase Database here).  So you'll either need to remove getContacts() from Profile, make it private, or add the @Exclude annotation to prevent it from being serialized.

Hope this helps,
-Michael

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/561121af-6ad9-4f7a-bdb3-fd19b1fa4979%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

GmailMe

unread,
Jun 27, 2016, 4:42:30 PM6/27/16
to fireba...@googlegroups.com
getContacts is not part of the profile model. Thanks for this. 

Sent from my iPhone 6
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/pattA7z-njE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages