【发布时间】:2019-02-12 22:47:23
【问题描述】:
我正在将文档添加到 Firebase 的 Cloud Firestore 中的集合中并不断收到此异常:
java.lang.IllegalArgumentException:无效数据。不支持的类型:com.example.com.myproject.PickUpDate(在字段 pick_up 中找到)
我以以下方式存储对象:
private fun storeData() {
val db = FirebaseFirestore.getInstance()
val offerDocument = HashMap<String, Any?>()
offerDocument.put(Key.CATEGORY, offer.category)
offerDocument.put(Key.ITEM_TYPE, offer.itemType)
offerDocument.put(Key.BRAND, offer.brand)
offerDocument.put(Key.PRICE, offer.price)
offerDocument.put(Key.PICK_UP_DATE, offer.pickUpPickUpDate)
offerDocument.put(Key.AVAILABILITY, offer.availability)
offerDocument.put(Key.COLOR, offer.color)
offer.images = adapter?.list?.map { it.toString() }
offerDocument.put(Key.IMAGES, offer.images)
// Add a new document with a generated ID
db.collection("offers")
.add(offerDocument)
.addOnSuccessListener { documentReference -> Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.id) }
.addOnFailureListener { e -> Log.w(TAG, "Error adding document", e) }
}
我的 PickUpDate 课程如下:
data class PickUpDate(var year : Int, var month : Int, var day : Int){}
可能是什么原因?为什么异常是专门针对这个类而不是其他类抛出的?
【问题讨论】:
-
你有其他类没有任何错误的例子吗?
-
@cricket_007 查看类别类:数据类 Category(var name: String, var id: Int)
标签: java android firebase kotlin google-cloud-firestore