Android Kotlin firebase.database.DatabaseException:在类上找不到要序列化的属性 [英] Android Kotlin firebase.database.DatabaseException: No properties to serialize found on class
本文介绍了Android Kotlin firebase.database.DatabaseException:在类上找不到要序列化的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了其他SO解决方案的建议: 1.使我的课程可序列化 2.具有Firebase的默认构造函数 3.更新我的proguard规则(不确定这一规则)
I have followed the advice of other SO solution: 1. Make my class Serializeable 2. Have a default constructor for Firebase 3. Update my proguard rules (Not sure about this one)
仍然出现上述错误,有什么想法吗?
And still I get the above error, any ideas?
package org.sherman.android.stub_firebase.Models
import java.io.Serializable
/**
* Created by fyi2 on 2/21/18.
*/
class User(displayName:String, email:String, photoUrl:String, userId:String) : Serializable {
constructor(): this("","","","")
}
新类定义:
class User :Serializable {
private var displayName:String=""
private var email:String=""
private var photoUrl:String=""
private var userId:String=""
constructor() {}
constructor(displayName: String, email: String, photoUrl: String, userId: String) {
this.displayName = displayName
this.email = email
this.photoUrl = photoUrl
this.userId = userId
}
}
保护规则:
-keepclassmembers class org.sherman.android.stub_firebase.Models.** { *; }
调用它的代码:
fun registerUserToFirebase(email:String, password:String){
mAuth?.createUserWithEmailAndPassword(email, password)?.addOnCompleteListener(this){ task ->
if (task.isSuccessful){
mProgressDialog?.dismiss()
var currentUserFB = task.getResult().user as FirebaseUser
var user = User("Bobby", currentUserFB!!.email!!, "", currentUserFB!!.uid)
mUsersDB!!.child(currentUserFB.uid).setValue(user)
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
} else {
Helper.showAlertDialog("Error!",task.exception?.message!!,this)
}
}
}
错误日志片段:
com.google.firebase.database.DatabaseException: No properties to serialize found on class org.sherman.android.stub_firebase.Models.User
at com.google.android.gms.internal.zzelx.<init>(Unknown Source:799)
at com.google.android.gms.internal.zzelw.zzf(Unknown Source:12)
at com.google.android.gms.internal.zzelw.zzbx(Unknown Source:259)
at com.google.android.gms.internal.zzelw.zzbw(Unknown Source:0)
at com.google.firebase.database.DatabaseReference.zza(Unknown Source:10)
at com.google.firebase.database.DatabaseReference.setValue(Unknown Source:7)
at org.sherman.android.stub_firebase.Activities.RegisterActivity$registerUserToFirebase$1.onComplete(RegisterActivity.kt:59)
推荐答案
已解决,即使在Kotlin中,变量似乎也必须明确地设为Public.
Solved, even in Kotlin it seems the variables had to be explicitly Public.
import java.io.Serializable
/**
* Created by fyi2 on 2/21/18.
*/
class User :Serializable {
public var displayName:String=""
public var email:String=""
public var photoUrl:String=""
public var userId:String=""
constructor() {}
constructor(displayName: String, email: String, photoUrl: String, userId: String) {
this.displayName = displayName
this.email = email
this.photoUrl = photoUrl
this.userId = userId
}
}
一旦被修改,其余的将照常工作.
Once that was modified, the rest worked as is.
这篇关于Android Kotlin firebase.database.DatabaseException:在类上找不到要序列化的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文