[英]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("Coin: ${autoCoin += 1}") bindingSub.tvAutoCoin.setText("硬币:${autoCoin += 1}")
I tried really hard to fix this error, but I couldn't fix it.我非常努力地修复了这个错误,但我无法修复它。
Even if the code is dirty, I would appreciate it if you understand...即使代码很脏,如果您理解,我将不胜感激...
You are assigning a new value in this line to the autoCoin
variable:您在这一行中为autoCoin
变量分配了一个新值:
bindingSub.tvAutoCoin.setText("Coin: ${autoCoin += 1}")
String templates only allow expressions.字符串模板只允许表达式。 An expression is something that results in a value of some type, even if that type is Unit and can be on the right hand side of an assignment statement (eg val x = 3
assigns the value of the expression 3
to x
).表达式是产生某种类型值的东西,即使该类型是 Unit 并且可以位于赋值语句的右侧(例如val x = 3
将表达式3
的值赋给x
)。 Some languages (like Java or C++) assignments are expressions, but in Kotlin they are not.某些语言(如 Java 或 C++)赋值是表达式,但在 Kotlin 中它们不是。
The x += 1
operator is a special shorthand syntax for x = x + 1
. x += 1
运算符是x = x + 1
的特殊速记语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.