首页 > 解决方案 > 未解决对 Firestore 侦听器上的任务结果数据的引用

问题描述

我有这种方法尝试从 Firestore 中检索文档,但由于某种原因,我收到一个错误:task.result.data 中的“未解析的引用:数据”,我可能错过了什么?

在此处输入图像描述

  import android.util.Log
  import com.google.firebase.firestore.FirebaseFirestore

    val db = FirebaseFirestore.getInstance()
    val docRef = db.collection("Cocab").document("Keys").collection("allkeys")

    // do something
    docRef.get().addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val document = task.result
            if (document != null) {
                Log.d("mate", "DocumentSnapshot data: " + task.result.data)
            } else {
                Log.d("mate", "No such document")
            }
        } else {
            Log.d("mate", "get failed with ", task.exception)
        }
    }
        .addOnFailureListener { exception ->
            Log.d("mate", "get failed with ", exception)
        }

标签: androidfirebasekotlingoogle-cloud-firestorelistener

解决方案


推荐阅读