【发布时间】:2021-09-30 03:27:35
【问题描述】:
var notify = ArrayList<String>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main_user)
btn_list2.setOnClickListener {
val sharedPreferences1 = getSharedPreferences("id", Context.MODE_PRIVATE)
val documentid: String? = sharedPreferences1.getString("id","null")
val c = FirebaseFirestore.getInstance()
val d = c.collection("applicationForm").document(documentid.toString()).get()
.addOnSuccessListener { document ->
notify = document?.get("notifyTo") as ArrayList<String>
var str1 = notify.joinToString()
Toast.makeText(applicationContext,str1,Toast.LENGTH_SHORT).show()
}}}
在notify = document?.get("notifyTo") as ArrayList<String> 行中出现错误。
这是我的 logcat 详细信息
java.lang.NullPointerException: null cannot be cast to non-null type java.util.ArrayList<kotlin.String>
at com.example.bloodbankcompany.MainActivityUser.onCreate$lambda-4$lambda-3(MainActivityUser.kt:47)
at com.example.bloodbankcompany.MainActivityUser.lambda$cGlrfLFSOO25IeEAacXMuz6Tzx0(Unknown Source:0)`.
请任何人帮忙。在这里,我正在尝试从 firestore 读取数组文档。
【问题讨论】:
-
您的
document为空或不包含notifyTo字段。
标签: android arrays kotlin google-cloud-firestore nullpointerexception