testtest
testtest

Reputation: 35

Kotlin: Expecting ')' error, code not running

I am fairly new to kotlin and below is my code. The result I am expecting should be "Hello Kotlin" but I keep getting an error and am not sure why.

 fun sayHello(itemtogreet:String){
        val msg = "Hello" + itemtogreet
        println(msg)
    }
    
    fun main(){
         sayHello(itemtogreet:"Kotlin")
    }

Upvotes: 1

Views: 175

Answers (3)

张笑笑
张笑笑

Reputation: 11

This is also occered to me,But the reason is Kotlin.kt calling Java.class. Wrong writing:

MigrationHelper.updateTableColumn(db, UserDao.class)

Right writing:

MigrationHelper.updateTableColumn(db = db, daoClass = UserDao::class.java)

Upvotes: 0

Retr0
Retr0

Reputation: 1

fun sayHello(itemtogreet:String){
    val msg = "Hello" + itemtogreet;
    println(msg)
}

fun main(){
    sayHello(" Kotlin")
}

Upvotes: -1

Nicola Gallazzi
Nicola Gallazzi

Reputation: 8723

It's a syntax problem, you have two options:

  1. removing parameter name
fun sayHello(itemtogreet:String){
  val msg = "Hello" + itemtogreet
  println(msg)
}
    
fun main(){
  sayHello("Kotlin")
}
  1. Use an explicit parameter name (useful only if you have more than one parameter) :
fun sayHello(itemtogreet:String){
  val msg = "Hello" + itemtogreet
  println(msg)
}
    
fun main(){
  sayHello(itemtogreet = "Kotlin")
}

Upvotes: 2

Related Questions