包裹:无法编组值 com.google.firebase.firestore.DocumentReference

问题描述

我在 Cloud Firestore 中存储了一个参考列表。当我得到数据时,它给了我这个错误

java.lang.RuntimeException:包裹:无法编组值 com.google.firebase.firestore.DocumentReference@44bef898”

我在互联网上搜索过,但没有找到任何解决方案。提前致谢

用户.kt

import android.os.Parcelable
import com.google.firebase.firestore.DocumentReference
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue

@Parcelize
data class User(
    val bio: String? = null,val email: String? = null,val followers: @RawValue List<DocumentReference>? = null,val following: @RawValue List<DocumentReference>? = null,val picture: String? = null,val uid: String? = null,val username: String? = null
) : Parcelable

解决方法

您收到以下错误:

"java.lang.RuntimeException: Parcel: 无法编组值 com.google.firebase.firestore.DocumentReference

因为您的 User 类实现了 Parcelable,并且其中的所有字段也应该实现 Parcelable,但它没有实现,因为属性 followersfollowing 的类型都是 {{ 1}} 和 DocumentReference实现 Parcelable 和 Serializable。要解决此问题,您应该从以下帖子中查看我的回答:

并使用每个 DocumentReference 对象中存在的 String 路径。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...