简体   繁体   中英

Can't run kotlin project

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.

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

It's possible, that the .classpath file is wrong, maybe because you moved your project. I found a solution for your problem here :

  1. Delete .classpath and .project from your project
  2. Delete your project in eclipse. DO NOT check delete project contents on disk.
  3. Now, in a file explorer, go into $yourworkspace/.metadata.
  4. Search for $yourprojectname
  5. Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
  6. In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
  7. Right click your project > properties > Java Build Path > Source tab
  8. Select all source folders, remove.
  9. Add folder, select src (whatever your src folder is called) and add it
  10. Go to libraries tab
  11. Add any jars to your build path here. There should be no more errors on your project now.
  12. 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.

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM