![](/img/trans.png)
[英]Assignments are not expressions and only expressions are allowed in this context - Kotlin
[英]Assignments are not expressions, and only expressions are allowed in this context - Kotlin
bindingSub.btnCoinup.setOnClickListener {
fbFirestore?.collection("users")?.document(fbAuth?.uid.toString())?.get()?.addOnSuccessListener { document ->
if (document != null) {
var autoCoin = document.data?.values.toString().replace("[", "").replace("]", "").toLong()
bindingSub.tvAutoCoin.setText("Coin: ${autoCoin += 1}")
} else {
bindingSub.tvAutoCoin.setText("Coin: 0")
}
} ?.addOnFailureListener { exception ->
...
bindingSub.tvAutoCoin.setText("硬币:${autoCoin += 1}")
我非常努力地修复了这个错误,但我无法修复它。
即使代码很脏,如果您理解,我将不胜感激...
您在这一行中为autoCoin
变量分配了一个新值:
bindingSub.tvAutoCoin.setText("Coin: ${autoCoin += 1}")
字符串模板只允许表达式。 表达式是产生某种类型值的东西,即使该类型是 Unit 并且可以位于赋值语句的右侧(例如val x = 3
将表达式3
的值赋给x
)。 某些语言(如 Java 或 C++)赋值是表达式,但在 Kotlin 中它们不是。
x += 1
运算符是x = x + 1
的特殊速记语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.