Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin - Error: Could not find or load main class _DefaultPackage

Tags:

kotlin

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?

like image 875
Francis Fredrick Valero Avatar asked Nov 29 '15 04:11

Francis Fredrick Valero


People also ask

What is the Error Could not find or load main class?

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.

Could not find or load main class helloworld class?

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.

Could not find or load main class cmd Error?

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.


1 Answers

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.

like image 142
goodwinnk Avatar answered Sep 23 '22 15:09

goodwinnk