Ad

Android Application Crash Using Firebase Realtime Database In Android Studio IDE

I'm making an Android app connected to Firebase and I'm using Realtime Database in it.

The problem is that the app, that I've installed on the emulator keeps crashing after user logs in.

I think it's a problem related to the fact that somehow the app is unable to retrieve user's data from the database. I've checked Firebase Documentation but nothing helped me. All my Gradle files are set up and sync correctly. I'm really stuck and don't know what to do.

Please help me I would be really grateful.

PS This is what is shown by Android Studio in the RUN SECTION when the app crashes

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.e.youdemo, PID: 26450
    com.google.firebase.database.DatabaseException: No properties to serialize found on class com.e.youdemo.UserProfile
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:[email protected]@17.0.0:530)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:[email protected]@17.0.0:312)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:[email protected]@17.0.0:413)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:[email protected]@17.0.0:214)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:[email protected]@17.0.0:79)
        at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:[email protected]@17.0.0:212)
        at com.e.youdemo.Menu$1.onDataChange(Menu.java:91)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:[email protected]@17.0.0:75)
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:[email protected]@17.0.0:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:[email protected]@17.0.0:55)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

EDIT

This is the method wich starts at line 91 of "Menu Activity" reported in the log

public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    UserProfile userProfile = dataSnapshot.getValue (UserProfile.class);
    CurrentUserName.setText (Objects.requireNonNull (userProfile).getName ());
    CurrentUserAge.setText (MessageFormat.format ("{0} anni", userProfile.getAge ()));
    CurrentUserGender.setText (userProfile.getGender ());
    CurrentUserWeight.setText (MessageFormat.format ("{0} kg", userProfile.getWeight ()));
    CurrentUserHeight.setText (MessageFormat.format ("{0} cm", userProfile.getHeight ()));
}

EDIT

package com.e.youdemo;

import java.io.Serializable;

public class UserProfile implements Serializable {
    private String Name;
    private String Age;
    private String Gender;
    private String Weight;
    private String Height;

    public UserProfile () {}

    UserProfile(String Name, String Age, String Gender, String Weight, String Height) {
        this.Name = Name;
        this.Age = Age;
        this.Gender = Gender;
        this.Weight = Weight;
        this.Height = Height;
    }

    String getName() {
        return Name;
    }

    String getAge() {
        return Age;
    }

    String getGender() {
        return Gender;
    }

    String getWeight() {
        return Weight;
    }

    String getHeight() {
        return Height;
    }

    void setName(String name) {
        Name = name;
    }

    void setAge(String age) {
        Age = age;
    }

    void setGender(String gender) {
        Gender = gender;
    }

    void setWeight(String weight) {
        Weight = weight;
    }

    void setHeight(String height) {
        Height = height;
    }
}
Ad

Answer

Replace

public class UserProfile implements Serializable {
    private String Name;
    private String Age;
    private String Gender;
    private String Weight;
    private String Height;
}

with

public class UserProfile implements Serializable {
    private String name;
    private String age;
    private String gender;
    private String weight;
    private String height;
}
Ad
source: stackoverflow.com
Ad