1

enter image description hereThis is a simple function in Kotlin (using intellij IDEA)

fun main() {
    println("HEllo World")
}

I expect print message but get nothing. What should I do?

Kotlin version: 1:10

Doi Hamada
  • 11
  • 2
  • Did you add the import line at the top of your code? – Kneecaps Jan 08 '22 at 09:24
  • 1
    @Kneecaps I don't think OP's code requires any imports. – Sash Sinha Jan 08 '22 at 09:25
  • @SashSinha some versions of kotlin need you to import pretty much everything. I think a lot of newer versions do the more common imports automatically but thought I would add it in if only to rule out the possibility – Kneecaps Jan 08 '22 at 09:31
  • 1
    I guess there is nothing wrong with your code. How do you execute it? How do you observe the results? What exactly does "nothing" mean? Empty screen, application freeze, some kind of an error? – broot Jan 08 '22 at 09:39
  • what package do I import ? – Doi Hamada Jan 08 '22 at 10:01
  • @broot "nothing" means empty screen and finished process. – Doi Hamada Jan 08 '22 at 10:03
  • [Kotlin fiddle](https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS42LjEwIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiLyoqXG4gKiBZb3UgY2FuIGVkaXQsIHJ1biwgYW5kIHNoYXJlIHRoaXMgY29kZS4gXG4gKiBwbGF5LmtvdGxpbmxhbmcub3JnIFxuICovXG5cbmZ1biBtYWluKCkge1xuICAgIHByaW50bG4oXCJIRWxsbyBXb3JsZFwiKVxufVxuIn0=), can't reproduce – Jerson Jan 08 '22 at 10:07
  • 5
    Is this a Kotlin script (`.kts` file)? If so, then all top-level code is executable and [`main` will never be invoked](https://stackoverflow.com/a/52542248/7366707). This might occur if you created a Kotlin [scratch file](https://www.jetbrains.com/help/idea/scratches.html) in IntelliJ, because those are created as Kotlin scripts instead of regular `.kt` files. – Salem Jan 08 '22 at 10:44
  • 1
    I don't think there is a Kotlin `1.10`. Which version are you really using? 1.1? Could you share how/where you specified the version? – Joffrey Jan 08 '22 at 11:20

1 Answers1

0

Try something like this

fun main(args: Array<String>) {
println("HEllo World")
}
skill347
  • 71
  • 9
  • I've already tried with (args: Array) and I get parameter args is never used warning. – Doi Hamada Jan 08 '22 at 09:41
  • That error is a warning error. It serves the purpose of alerting people in case you forgot to use that variable. However, your code should still compile and execute – Kypps Jan 08 '22 at 10:12
  • @Kypps please don't use Maven. Gradle is more adapted to work with Kotlin, as the Kotlin and the Gradle team are working together to make the experience better. Also, Gradle can be configured using Kotlin – Joffrey Jan 08 '22 at 11:15