'Unable to save firebase firestore with kotlin android
Now I'm running the firebase firestore example code.
Then failed to save and tried debugging using the println() function.
The debug results are output 1, 2, 3, 8.
The db.collection ("users") part is not running.
val firebaseTest:Button = findViewById(R.id.firebaseTest)
firebaseTest.setOnClickListener {
println(1)
val db = Firebase.firestore
println(2)
// Create a new user with a first and last name
val user = hashMapOf(
"first" to "Ada",
"last" to "Lovelace",
"born" to 1815
)
println(3)
// Add a new document with a generated ID
db.collection("users")
.add(user)
.addOnSuccessListener { documentReference ->
println(4)
Toast.makeText(this@LoginActivity, "success.", Toast.LENGTH_SHORT).show()
println(5)
}
.addOnFailureListener { e ->
println(6)
Toast.makeText(this@LoginActivity, "faild", Toast.LENGTH_SHORT).show()
println(7)
}
println(8)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
