问题描述
我在 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,但它没有实现,因为属性 followers
和 following
的类型都是 {{ 1}} 和 DocumentReference 不不实现 Parcelable 和 Serializable。要解决此问题,您应该从以下帖子中查看我的回答:
并使用每个 DocumentReference 对象中存在的 String 路径。