为什么我不能显示来自 Firebase 的数据?

Why can't I display my data from firebase?

我遇到了问题,因为我无法显示来自 firestore 的数据。我想从 xml 中获取我的 ID。我在视频的帮助下写了这个,当他们写下 id 时,它会立即得到它,但我的没有。
This is the video

主要activity.kt

private fun retrivePerson() = CoroutineScope(Dispatchers.IO).launch {
    try {
        val querySnapshot = personCollectionName.get().await()
        val sb = StringBuilder()
        for (document in querySnapshot.documents) {
            val users = document.toObject<users>()
            sb.append("$users\n")
        }
        withContext(Dispatchers.Main) {
            uzytkownik.text = sb.toString()
           /* val imie = findViewById<TextView>(R.id.uzytkownik).apply {

                text = "Witaj, " + sb.toString()*/
            }
        }
    } catch (e: Exception) {
        withContext(Dispatchers.Main) {
            Toast.makeText(this@MainActivity, e.message, Toast.LENGTH_LONG).show()
        }
    }

主要xml

 <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="245dp"
        android:layout_height="66dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/uzytkownik"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Witaj,"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

    </ScrollView>

错误用户 ID

在视频中,他使用了 KotlinX.synthetics,这是一种在您的代码中访问 XML 视图组件的方法。这实际上已被弃用,因为您应该改用 View Binding