Skip to content Skip to sidebar Skip to footer

Error When Getting An Object From Datasnapshot

I am implementing a database with Firebase for an android application. I present 2 beans : User.class and Address.class, using by the app : @IgnoreExtraProperties public class User

Solution 1:

Seems like one(or some) of the User nodes has an address field of type String. Surround it with try catch and log both the exception and key of the node to find the culprit(s).

 usersRef.addChildEventListener(newChildEventListener() {

        @OverridepublicvoidonChildAdded(DataSnapshot dataSnapshot, String s) {

           try{
                User user = dataSnapshot.getValue(User.class);
            }
            catch(DatabaseException e){
                //Log the exception and the key 
                dataSnapshot.getKey();
            }
         }

            ...

}

Solution 2:

The error relates to Firebase trying to marshal the address value under one of the user nodes into an Address class instance.

The address value in the database should match your class Address, but one of them is a string which can't be converted to an Address instance.

If the address value is supposed to be a string, you'll need to change the type of the address field on the User class to String:

privateString address;

Otherwise, you'll need to check each node under user in your database for any that incorrectly have a string for the address value.

Post a Comment for "Error When Getting An Object From Datasnapshot"