I followed the Kotlin tutorial for eclipse here : Getting Started With Eclipse Luna
However, I'm running into this error:
Error: Could not find or load main class _DefaultPackage
Anyone who knows to get around this?
The "Could not find or load main class" error occurs when the JVM fails to load the main class. This can happen due to various reasons, such as: The class being declared in the incorrect package. The file path of the class not matching the fully qualified name.
Wrong Class Name And it failed with the error “Could not find or load main class helloworld.” As discussed earlier, the compiler will generate the . class file with the exact same name given to the Java class in the program. So in our case, the main class will have the name HelloWorld, not helloworld.
The error 'Could not find or load main class' occurs when using a java command in the command prompt to launch a Java program by specifying the class name in the terminal. The reason why this happens is mostly due to the user's programming mistake while declaring the class.
This was a severe bug (KT-10221) in automatic generation of Launch Configuration in plugin version 0.4.0. It was fixed in 0.5.0 so the recommendend way to workaround is to update plugin.
The source of the problem was that the plugin used an old pattern for generating name of the class for main function that had been abandoned by Kotlin compiler.
It's possible to workaround it by editing launch configuration (Eclipse Menu -> Run -> Run Configurations...) by hand and changing Main class field in Java Application group. If the file is named hello.kt with no package directive, as it is described in tutorial, than corrected string should be HelloKt.
If file has name other.kt with package my.tutorial than the Main Class should contain my.tutorial.HelloKt. You can read more about it in the section Package-Level Functions of Calling Kotlin From Java page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With