Home > Back-end >  Correct way to use Kotlin with Command Line and VS Code
Correct way to use Kotlin with Command Line and VS Code

Time:09-18

I have a file hello.kt which I'm editing in VSCode. When I tried a simple Hello World:

fun main() {
    println("Hello, World!");
}

and compiled the file with kotlinc hello.kt followed by java HelloKt, the program worked fine.

However, when I change my file to:

fun main() {
    val c = sum(2, 3);
    println("The sum of 2 and 3 is $c");
}
fun sum(x: Int, y: Int): Int {
    return x   y;
}

and run the same commands, I get an error.

        at HelloKt.main(hello.kt:4)
        at HelloKt.main(hello.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
        ... 2 more

The official enter image description here

  • Related