Reputation: 1
I am brand new to kotlin. I have installed kotlin plugins to eclipse. I found the simple example posted below in one of the tutorials. The issue is, when I run the project i receive the below stated error.
To solve this issue I tried to run the project as kotlin application, but I could not find that option at all.
please let let me know how to fix this error?
code:
fun main(args : Array) {
println("Hello, World!")
}
error:
Error: Could not find or load main class com.example.Main
update:
to solve this issue I followed exactly what is in this tutorial and I installed the most recent version of eclipse PHOTON but still the problem is there.
Upvotes: 2
Views: 1526
Reputation: 304
The main function in Kotlin is different. You need to add <> wrapping the String to the function, and it should look like this:
fun main(args : Array<String>) {
println("Hello, World!")
}
Then your program should compile :-)
Upvotes: 0
Reputation: 518
if your main function is a top level function (not wrapped in a class or object)
then the generated class will be FIlenameKt, or for your case MainKt
assuming it is in Main.kt
Upvotes: 1
Reputation: 304
It's possible, that the .classpath file is wrong, maybe because you moved your project. I found a solution for your problem here:
- Delete .classpath and .project from your project
- Delete your project in eclipse. DO NOT check delete project contents on disk.
- Now, in a file explorer, go into $yourworkspace/.metadata.
- Search for $yourprojectname
- Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
- In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
- Right click your project > properties > Java Build Path > Source tab
- Select all source folders, remove.
- Add folder, select src (whatever your src folder is called) and add it
- Go to libraries tab
- Add any jars to your build path here. There should be no more errors on your project now.
- Run your project like you normally would.
If you want to test your code, you can also do that online on the Kotlin website here.
I hope this could help you.
Upvotes: 0