Firebase “User is missing a constructor with no arguments”

后端 未结 4 2080
不知归路
不知归路 2020-12-14 18:28

I am trying to retrieve my user details from the /User/ tree i have in Firebase. I have the following User object :

public class User {
    private String          


        
4条回答
  •  既然无缘
    2020-12-14 18:58

    I have faced this in kotlin with firebase realtime database and solve it by this solution

    For Kotlin, if you're using data class like below for firebase,

    data class UserModel(
            var UserName: String,
            var UserType: Int
    )
    

    then you'll get an error like

    com.google.firebase.database.DatabaseException: UserModel does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.

    So for this, you need to initialize its values.

    data class UserModel(
            var UserName: String = "",
            var UserType: Int = 0
    )
    

提交回复
热议问题