There is a certain base FireBase Real-time Database.

EmainAuth.java

private void writeNewUser(String userId, String email) { // TODO FIX BUG: CANNOT SEND AN EMAIL TO FIREBASE DB Log.d(TAG, "Email in writeNewUser(): " + email); UserAccount user = new UserAccount(email); mDatabase = FirebaseDatabase.getInstance().getReference(); mDatabase.child("Users").child(userId).setValue(user); } 

UserAccount.java

 import android.util.Log; public class UserAccount { public final static String TAG = "tag"; String username; int rating; String email; public UserAccount(){} public UserAccount(String email){ // TODO CHECK WHAT'S WRONG- EMAIL COULD BE EMPTY Log.d(TAG, "Email is UserAccount constructor: " + email); this.email = email; this.rating = 1; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public int getRating() { return rating; } public void setRating(int rating) { this.rating = rating; } } 

What is displayed in the console:

Email in writeNewUser (): jxgdiy@idgdgu.hx

Email is UserAccount constructor: jxgdiy@idgdgu.hx

As a result, only this enters the database:

 { "Users" : { "G5bIG92W4sS3XFtdKFqAUVGAfm43" : { "rating" : 1 } } } 

Where does the email field go? And in general, before it was necessary to send 2 lines, and both of them were sent. How to make lines appear in the Firebase Database?

    1 answer 1

    It's simple. In order for Firebase DB to operate with class objects without problems, you need to specify a getter and a setter for each field, because this is the only way Firebase DB can interact with the fields of your class. In your case, specifically, there is a lack of a getter to receive email. And if you were recording data into an object, you would need a setter. Therefore, I advise you to add immediately and getter and setter.

    Another addition to the future, to ignore the field that has a getter and a setter, you need to add the @Ignore annotation.

    You can read in detail here .

    • Thank you very much! I neglected this line due to my carelessness: "I’ve repeatedly reread it) - timuruktus
    • One more question. Is it important that the empty constructor required to write an object does not contain any code? - timuruktus
    • one
      No, it does not matter, I checked. With the code, too, everything works. - Arnis Shaykh