[英]Android Kotlin - Unexpected tokens (use ';' to separate expressions on the same line)
[英]Unexpected tokens (use ';' to separate expressions on the same line)
我不知道為什么我寫這個Kotlin代碼時遇到了這樣的問題
Log.d(TAG, msg:"onCreate called. Score is :$score")
我假設您正在嘗試使用命名參數,並將msg
判斷為Log.d
第二個參數的Log.d
,並在您的代碼Log.d
其匹配。 但是,您確實有兩個問題:
=
,而不是:
如您所能:
data class SomeClass(val x: String, val y: String)
fun someFunction(){
SomeClass(y = "y", x = "x")
}
但是您不能為Log.d
做到這Log.d
,因為它不是Kotlin函數。 作為參考,這是適當的語法:
Log.d(TAG, msg="onCreate called. Score is :$score")
但是它不會編譯,因為Named arguments are not allowed for non-Kotlin functions
。 因此將其刪除。 您不能在該方法中使用命名參數。
刪除“ msg:”
Log.d(TAG, "onCreate called. Score is :$score")
嘗試使用Log.d(TAG,“ msg:onCreate被調用。得分為:$ score”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.