【问题标题】:Parcel: unable to marshal value com.google.firebase.firestore.DocumentReference包裹:无法编组值 com.google.firebase.firestore.DocumentReference
【发布时间】:2021-03-05 08:35:22
【问题描述】:

我将引用列表存储在 Cloud Firestore 中。当我得到数据时,它给了我这个错误:

“java.lang.RuntimeException: Parcel: 无法编组值 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

【问题讨论】:

  • 我认为,DocumentReference 不是Parcelable。您如何存储项目列表?
  • 您是指 DocumentReference 的列表吗?因为我可以使用 DocumentReference 本身

标签: android firebase kotlin google-cloud-firestore parcelable


【解决方案1】:

您收到以下错误:

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

因为您的User 类实现了 Parcelable,并且其中的所有字段也都应该实现 Parcelable,但事实并非如此,因为 followersfollowing 的两个属性都属于 List&lt;DocumentReference&gt;DocumentReference 类型实现 Parcelable,也不实现 Serializable。要解决这个问题,您应该从以下帖子中查看我的答案:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 2016-03-19
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多