Firebase Firestore 数据无法在 RecyclerView 中获取和打印

firebase firestore data is not able to get and print in recyclerview

提问人:Raunak ali 提问时间:5/8/2021 最后编辑:Raunak ali 更新时间:5/9/2021 访问量:86

问:

适用于 Android 应用的 Kotlin 代码

这是用于从 firebase firestore 数据库读取数据的代码。但无法从 Firestore 数据库中获取数据,代码中的 FALT 在哪里

logcat 中显示以下两个错误:

2021-05-09 02:12:26.315 19481-19481/?E/raunak.alison_:runtime_flags中设置的未知位:0x8000



2021-05-09 02:12:26.828 19481-19481/com.raunak.alison_4 E/libc:访问被拒绝查找属性“ro.vendor.df.effect.conflict”

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.auth.User
import kotlinx.android.synthetic.main.activity_home.*
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.comment_list_view.*
import java.util.*

class home : AppCompatActivity() {
    var selectCategery = Funny
    lateinit var commentAdopter: CommentAdopter
    val comment_detail = arrayListOf<data_constructer>()
    val commentClollectionRef = FirebaseFirestore.getInstance().collection(Reference_data)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)


        commentAdopter = CommentAdopter(comment_detail)
        recycler_list_view.adapter = commentAdopter
        val layoutManager = LinearLayoutManager(this)
        recycler_list_view.layoutManager = layoutManager
        commentClollectionRef.get()
            .addOnSuccessListener { snapshot ->
                for (document in snapshot.documents) {
                    val data = document.data


                    val name = data!![USERNAME] as String
                    val timestamp = data[TIMESTAMP] as Date
                    val comment = data[COMMENT] as String
                    val numLikes = data[NUM_LIKES] as Long
                    val numComments = data[NUM_COMMENTS] as Long
                    val documentId = document.id

                    val newThoughts = data_constructer(
                        name,
                        timestamp,
                        comment,
                        numLikes.toInt(),
                        numComments.toInt(),
                        documentId
                    )

                    comment_detail.add(newThoughts)


                }
                commentAdopter.notifyDataSetChanged()

            }.addOnFailureListener { exception ->

                Log.e("Exception", "Could not add post:$exception")

            }

    }


    fun mainFunnyClicked(view: View) {


        if (selectCategery == Funny) {
            main_funnyBtn.isChecked = true
            return
        }
        main_seriousBtn.isChecked = false
        main_crazyBtn.isChecked = false
        main_populerBtn.isChecked = false
        selectCategery = Funny

    }

    fun mainSeriousClicked(view: View?) {
        if (selectCategery == SERIOUS) {
            main_seriousBtn.isChecked = true
            return
        }
        main_funnyBtn.isChecked = false
        main_crazyBtn.isChecked = false
        main_populerBtn.isChecked = false
        selectCategery = SERIOUS

    }

    fun mainCrazyClicked(view: View?) {
        if (selectCategery == CRAZY) {
            main_crazyBtn.isChecked = true
            return
        }
        main_seriousBtn.isChecked = false
        main_funnyBtn.isChecked = false
        main_populerBtn.isChecked = false
        selectCategery = Funny

    }

    fun mainPopulerClicked(view: View?) {
        if (selectCategery == POPULAR) {
            main_populerBtn.isChecked = true
            return
        }
        main_seriousBtn.isChecked = false
        main_funnyBtn.isChecked = false
        main_crazyBtn.isChecked = false
        selectCategery = Funny

    }
}

当我注释下面的代码时:应用程序运行良好。

commentClollectionRef.get()
        .addOnSuccessListener { snapshot ->
            for (document in snapshot.documents) {
                val data = document.data

                val name = data!![USERNAME] as String
                val timestamp = data[TIMESTAMP] as Date
                val comment = data[COMMENT] as String
                val numLikes = data[NUM_LIKES] as Long
                val numComments = data[NUM_COMMENTS] as Long
                val documentId = document.id

                val newThoughts = data_constructer(
                    name,
                    timestamp,
                    comment,
                    numLikes.toInt(),
                    numComments.toInt(),
                    documentId
                )

                comment_detail.add(newThoughts)
            }
            commentAdopter.notifyDataSetChanged()

        }.addOnFailureListener { exception ->
            Log.e("Exception", "Could not add post:$exception")
        }

如何从Firestore数据库中读取数据,给我简单的 Kotlin 的代码示例,如果我想上传和读取数据......如 以及Firebase上的图像。帮帮我

Android Kotlin Firebase-realtime-database android-recyclerview 语法错误

评论

0赞 clamentjohn 5/8/2021
你好。欢迎来到 SO。尝试改革问题,以便我们了解您的要求。请不要转储代码,并期望我们神奇地解决它。
0赞 Frank van Puffelen 5/8/2021
如果应用程序崩溃,其 logcat 输出中将出现错误消息和堆栈跟踪。请找到这些并将它们添加到您的问题中。
0赞 Alex Mamo 5/10/2021
如果应用崩溃,则会出现堆栈跟踪。请在 logcat 上查找,并将其添加到您的问题中。也请回复@。

答: 暂无答案