I'm trying get data from Firestore. I get the data successfully.
Log.i("FirestoreClass", "$document")
resulted in the document from the firestore. But while coverting it to a object of User class:
@Parcelize
data class User(
var id : String?,
var email : String?,
var profileHeadline : String? = "",
var profileSummary : String? = "",
var profilePhoto : String? = "",
var personalInfo: PersonalInfo? = PersonalInfo(),
var education: List<Education>? = listOf(Education()),
var experience: List<Experience>? = listOf(Experience()),
var skills : List<Skills>? = listOf(Skills()),
var languages: List<Languages>? = listOf(Languages()),
var interest : List<Interest>? = listOf(Interest()),
var awardAndAchievements: List<AwardAndAchievements>?
= listOf(AwardAndAchievements()),
var licenceAndCertification: List<LicenceAndCertification>?
= listOf(LicenceAndCertification()),
var projects : List<Projects>? = listOf(Projects()),
var publications: List<Publications>? = listOf(Publications()),
var patents : List<Patents> = listOf(Patents()),
var volunteerExperience : List<VolunteerExperience>?
= listOf(VolunteerExperience()),
var recommendations: List<Recommendations>? = listOf(Recommendations()),
var customSectionOneLine : List<CustomSectionOneLine>?
= listOf(CustomSectionOneLine()),
var customSectionTwoLine : List<CustomSectionTwoLine>?
= listOf(CustomSectionTwoLine()),
var fcmToken : String? = ""
) : Parcelable
I got an error in the logcat.
2022-09-02 19:12:04.826 7195-7195/com.example.theresumebuilder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.theresumebuilder, PID: 7195
java.lang.RuntimeException: Could not deserialize object. Class com.example.theresumebuilder.models.User does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped
at com.google.firebase.firestore.util.CustomClassMapper.deserializeError(CustomClassMapper.java:568)
at com.google.firebase.firestore.util.CustomClassMapper.access$200(CustomClassMapper.java:57)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:754)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:746)
at com.google.firebase.firestore.util.CustomClassMapper.convertBean(CustomClassMapper.java:547)
at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(CustomClassMapper.java:258)
at com.google.firebase.firestore.util.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:103)
at com.google.firebase.firestore.DocumentSnapshot.toObject(DocumentSnapshot.java:183)
at com.google.firebase.firestore.DocumentSnapshot.toObject(DocumentSnapshot.java:161)
at com.example.theresumebuilder.firebase.FirestoreClass.getUserFromDatabase$lambda-2(FirestoreClass.kt:44)
at com.example.theresumebuilder.firebase.FirestoreClass.$r8$lambda$e6ebAYLyyLOhg0E7gq6xcXf2etE(Unknown Source:0)
at com.example.theresumebuilder.firebase.FirestoreClass$$ExternalSyntheticLambda2.onSuccess(Unknown Source:4)
at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.1:1)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
This is the code for Firestore:
fun getUserFromDatabase(activity: LoginActivity){
db.collection(Constants.USERS)
.document(getCurrentUUID())
.get()
.addOnSuccessListener {document->
Log.i("FirestoreClass","${document.toObject(User::class.java)}")
val loggedInUser = document.toObject(User::class.java)
activity.userDataFromDatabase(loggedInUser)
}
.addOnFailureListener {
activity.hideProgressDialog()
Toast.makeText(
activity,
it.message,
Toast.LENGTH_SHORT
).show()
}
}
I tried my best to find the way to solve this error but unable to find it. I'm tryna build a resume builder app. I think there is something with the User class, I've used many data classes to save the data of the user And at last compounded them in the User data class. If you need anything else. Please let me know. Thanks in advance.