Error for Hello World on Ubuntu

Hi kotlin-Experts,

I learned a bit about Kotlin on and find it a very interesting programming language. Therefore, I installed the kotlin compiler via sdkman as described here on a Ubuntu box.

Installation went ok, but compilation of the hello world example showed errors :frowning: (see code and output below)

Has anyone a hint what went wrong … I’m sure more complex source code can be consumed by the kotlin-compiler :slight_smile:
Perhaps the compiler has to be combined with specific JVM versions or similar.

Thanks for any help!

bkt:~/Develop/Kotlin$ cat hello.kt
fun main(args: Array) {
println(“Hello world.!”);

bkt:~/Develop/Kotlin$ kotlinc hello.kt -d hello.jar
Juli 28, 2017 11:23:33 VORM. sun.util.PropertyResourceBundleCharset$PropertiesFileDecoder decodeLoop
INFO: Invalid or unmappable UTF-8 sequence detected. Switching encoding from UTF-8 to ISO-8859-1
exception: java.lang.ArrayIndexOutOfBoundsException: 32768
at org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleInfo$
at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.computeAllSystemModules$kotlin_compiler(CliJavaModuleFinder.kt:28)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.computeRootModules(KotlinCoreEnvironment.kt:298)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.addModularRoots(KotlinCoreEnvironment.kt:277)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.convertClasspathRoots(KotlinCoreEnvironment.kt:269)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.(KotlinCoreEnvironment.kt:197)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.(KotlinCoreEnvironment.kt:109)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:423)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:240)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createEnvironmentWithScriptingSupport(K2JVMCompiler.kt:230)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:189)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
at org.jetbrains.kotlin.cli.common.CLICompiler.exec(
at org.jetbrains.kotlin.cli.common.CLICompiler.exec(
at org.jetbrains.kotlin.cli.common.CLICompiler.exec(
at org.jetbrains.kotlin.cli.common.CLICompiler.doMainNoExit(
at org.jetbrains.kotlin.cli.common.CLICompiler.doMain(
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:282)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-internal/Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(java.base@9-internal/
at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-internal/
at java.lang.reflect.Method.invoke(java.base@9-internal/
at org.jetbrains.kotlin.preloading.Preloader.main(

bkt:~/Develop/Kotlin$ java -version
openjdk version “9-internal”
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

I can see two things that are certainly wrong.

Firstly, your hello.kt isn’t quite right. It should be:

fun main(args: Array<String>) {
    println(“Hello world.!”)

Secondly, the command to create hello.jar from Ubuntu terminal should be:

kotlinc hello.kt -include-runtime -d hello.jar

Also I’m not sure whether the Kotlin compiler yet supports Java 9 though it certainly supports Java 8. Anyway, before doing anything about that, I’d see if the above two changes help.

One other thing I’ve just noticed, which I missed the first time around, is that you need to use the ordinary double-quote symbol (unicode 34) to delimit strings at both ends.

You appear to be using the opening and closing quote symbols (unicode 8220 and 8221) instead.

Hi alanfo,

thanks for the quick reply. The missing <String> must have been a copy-paste error, it was definitely in the code I tried.
I have also tried the -include-runtime version, without changes in the output.

Right now, I also checked the quote symbols after seeing your second answer, but unfortunately, this is also not the origin of my errors.
I used vi and nano editor and created hello.kt versions from scratch, both definitely had the unicode 34 double-quote symbols. But the observed error remained unchanged.

I think I will try to switch to Java 8 and then try again.


Hi again,

after switching to Java 8 (like this openjdk - Switch between multiple java versions - Ask Ubuntu)
the errors disappear!


Glad to hear you’ve sorted it out now by switching back to Java 8. :slight_smile:

According to this blog-post I’ve just found, the current stable version of Kotlin (1.1.3) does in fact provide initial support for compiling against Java 9, so the errors you were getting at first are still a bit puzzling.

However, I notice that you were using quite an old build (April 2016) of the Java 9 EAP and so perhaps this was the problem.