Stuck at first base starting with kotlin


#1

I am trying to evaluate kotlin for our team, so i wanted to try some code

I downloaded Intellij IDEA

found an up to date tutorial on getting started :

Found i had to set up a Run/debug configuration, and by trial and error a
’Main Class’ of ‘HelloKt’ for my Hello.kt file gets somewhere, but as I get the
error message:

Error running Hello: Top-level function ‘main’ not found in package ‘’

… perhaps that main class is not quite correct, or another settings is required?

Any help appreciated !

Code:

import com.sun.org.apache.xpath.internal.operations.String

/**

  • Created by innov8ian on 16/05/2017.
    */

fun main(args: Array){
println(“hello world”)
}


#2

The tutorial actually explains how you can run your application without any need for trial and error: “The easiest way is to click on the Kotlin icon in the gutter and select Run ‘AppKt’.”


#3

I am new to Intelij, and have not touched Java for years as this is not a team coming to Kotlin from Java.

his was new install of Intelij, not previously used with Java. It seems the real problem is something in the setup was wrong at the time the project was created, or some step was wrong.

This meant there was Kotlin icon in the gutter. At the time the project was created, Intelij had not yet been configured for the JVM. Not sure if this was the problem, as I still have that problem with the original project.

However I created and new project, and for that project the Koltin icon does appear in the gutter. I cannot find the difference in project files, but for this new project all works fine.

The key is if the Kotlin icon does not appear in the gutter, then there is an error with the project configuration, and it is not worth proceeding.

If I do discover what that error is, I will post again. So problem avoided, if not fully solved.


#4

this code is wrong

should be just this: without that weird sun String import

fun main(args: Array<String>)
{
    println("hello world")
}

#5

Yes, good point. That being import being added automatically by Intelij was another clue something is wrong in the configuration of that project. Same code works fine with a new project.

In fact, inspired by @scmellow i removed that import and ‘lo and behold’ the Kotlin icon in the gutter appeared! That import was added automatically, clearly when some setting, since correct, was wrong. So full solution, except perhaps for what wrong setting resulted in automatic generation of the import…