【发布时间】:2018-01-20 03:22:14
【问题描述】:
我实际上可以使用地图插入数据,但我不能使用我自己的类中的对象。在 Firestore 文档中,他们说我可以。
错误是:
java.lang.RuntimeException: No properties to serialize found on class com.example.alumne.rateit.core.model.Restaurant
任何帮助将不胜感激,谢谢。
class Restaurant(name: String, fiscName: String, cif: String, addr: String, city: String, phone: String, zipCode: String, country: String, email: String): Serializable{ }
override fun onClick(view: View?) {
when(view?.id){
btn_submit.id ->{
if (checkForEmptyField()){
val restName = et_rest_name.text.toString()
val restFiscName = et_fiscal_name.text.toString()
val restAddr = et_address.text.toString()
val restPhone = et_phone.text.toString()
val restZipCode = et_zip_code.text.toString()
val restCif = et_cif.text.toString()
val restCity = et_city.text.toString()
val restCountry = et_country.text.toString()
val restEmail = et_email.text.toString()
/*val restaurant: HashMap<String, String> = HashMap()
restaurant.put("name",restName)
restaurant.put("fiscName",restFiscName)
restaurant.put("address",restAddr)
restaurant.put("phone",restPhone)
restaurant.put("zipCode",restZipCode)
restaurant.put("cif",restCif)
restaurant.put("city",restCity)
restaurant.put("country",restCountry)
restaurant.put("email",restEmail)*/
val rest = Restaurant(restName,restFiscName,restCif,restAddr,restCity,restPhone,restZipCode,restCountry,restEmail)
if (bd.collection("restaurants").document().set(rest).isSuccessful){
Utilities.showMessage(view,"Restaurant added correctly")
}else{
Utilities.showMessage(view,"Error adding restaurant")
}
}else{
if (view != null) {
Utilities.showMessage(view,"Fill all fields")
}
}
}
}
}
【问题讨论】:
-
你能发布你收到的错误信息吗?
-
java.lang.RuntimeException:在类 com.example.alumne.rateit.core.model.Restaurant 上找不到要序列化的属性
-
用 Serializable 扩展 Restaurant 类。
-
告诉我们
Restaurant:错误说它不包含序列化它的属性... -
请编辑您的问题以显示您的餐厅课程的内容。另外,请记住 set() 方法是异步的并返回一个未解析的任务,您需要将侦听器附加到该任务以知道它何时完成。
标签: java android firebase kotlin google-cloud-firestore