In order to create my first, simple Kotlin project in Eclipse, I followed the steps in Getting Started with Eclipse Luna tutorial from Kotlin official website, i.e.:
main
methodHowever, I keep get the following error in Eclipse console:
Error: Could not find or load main class HelloKt
I have double-checked the Run Configuration for my project, and it does set the "Main class" as HelloKt
(which I'm 100% sure it does not exist). Also, when I hit the "Search" button, the only item that Eclipse finds is HelloKt - (default package)
(which, again, does not exist).
For the sake of completeness, find below the code for hello.kt
file:
fun main(args: Array<String>) { println("Hello, World") }
I noticed the following divergences between the tutorial and what I did:
jdk1.6.0_45
, while I'm using jdk1.7.0_79
.Note that I'm using the latest version of Kotlin Eclipse Plugin, so this is not the same case as in this post. These are the versions in my current installation:
Can any of these divergences be the cause of the error while running the application?
Do you see/know any potential cause or known bug regarding this scenario?
UPDATE (May 14th, 2017)
Tried with Eclipse Neon.3 (eclipse.buildId=4.6.3.M20170301-0400), JDK 1.8.0_111, Kotlin 0.8.2.v20170314-0957 (kotlin-eclipse-policy 0.8.2.v20170314-0957, kotlin-weaving-feature 0.8.2.v20170314-0957, Equinox Weaving SDK 1.2.0.201701131634). The problem persists.
To run the application, right-click somewhere in the main file and select Run As | Kotlin Application. If everything went well, you'll see the result in the Console window. Congratulations! You now have your Kotlin application running in Eclipse IDE.
Kotlin Plugin for Eclipse has limited support. Use other IDEs for Kotlin development, such as IntelliJ IDEA or Android studio, to get full support of new Kotlin features.
Select the project, right click Configure Kotlin > Add Kotlin Nature. Once that is done you will be able to work on it and run it as shown below. The simplest way to run the app is to select the DemoApplication. kt file in the package explorer, right click Run As > Kotlin Application.
Try new Kotlin File
instead of Kotlin Class
:
For me it happened only once. I think this is some glitch from the Kotlin plugin, when you first create a Kotlin file and try run it. Try "new Kotlin class" paste the same content and see if it works. After that you should be able to run both files as it happened to me.
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