![](/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.