【发布时间】:2020-12-22 18:39:31
【问题描述】:
错误是Variable 'uid2' must be initialized,我已经在它说这个的地方发表了评论。我的目标是从一个集合中查询一个 uid,然后将其插入到另一个集合中。
fun addFriend(username: String) {
var uid2: String
var docRef = firebaseFirestore.collection(collUsers).whereEqualTo("username", username)
.get()
.addOnSuccessListener { documents ->
for (document in documents) {
Log.d(tag, "${document.id} => ${document.data}")
uid2 = document.data.getValue("uid").toString()
Log.d(tag, "uid_2: $uid2")
}
}
.addOnFailureListener { exception ->
Log.w(tag, "Error getting documents: ", exception)
}
var collRelationships2: CollectionReference = firebaseFirestore.collection(collRelationships)
var relationshipsMap: HashMap<String, Any> = hashMapOf(
"uid_1" to firebaseAuth.uid.toString()
, "uid_2" to uid2 //Error is here
, "stat" to 1
, "createDate" to FieldValue.serverTimestamp()
, "modifiedDate" to FieldValue.serverTimestamp()
)
collRelationships2.add(relationshipsMap)
}
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore