Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我想在kotlin中使用setter来设置文档快照的值_Android_Firebase_Kotlin_Google Cloud Firestore - Fatal编程技术网

Android 我想在kotlin中使用setter来设置文档快照的值

Android 我想在kotlin中使用setter来设置文档快照的值,android,firebase,kotlin,google-cloud-firestore,Android,Firebase,Kotlin,Google Cloud Firestore,我尝试在kotlin中使用setter,但无法设置文档快照数据 private lateinit var document: QueryDocumentSnapshot //intialize top .addOnSuccessListener { documents -> for (document in documents) { klog.d("#f

我尝试在kotlin中使用setter,但无法设置文档快照数据


    private lateinit var document: QueryDocumentSnapshot
//intialize top
            .addOnSuccessListener { documents ->
                        for (document in documents) {
                            klog.d("#fail", document.get("question").toString())
                            setDocument(document)
                        }
                    }.addOnFailureListener { exception ->
                        klog.d("#fail", exception.message)
                    }
        }
    }

    fun setDocument(document: QueryDocumentSnapshot) {
        this.document=document
    }

尝试以下代码,检查变量是否已初始化

        if (::document.isInitialized){
            //variable is initialised
        }

我是kotlin的新手,任何帮助都将不胜感激。当我使用document变量时,会出现什么错误,就是说它不是初始值。如果您知道任何事情,请帮助我,@Peter Haddad你为什么要这样做
this.document=document
?不,我的问题是在document字段中设置数据基本上你正在尝试使用变量,在从firbase设置值之前,我建议,在设置值之后读取变量(在successlistener中回调之后)或者检查变量是否初始化,我正在编辑上面的答案,以检查变量是否初始化