1

I'm trying to run a basic Kotlin main file but the problem is I don't have any run/debug configurations available.

My main.kt file is under src>main and is a very simple Helloworld program. See below image. When I enter Add Configuration>Kotlin and type MainKt in Main Class, I get Warning: Class MainKt not found. In previous projects MainKt has been the default and I haven't had to add a configuration manually. Has anyone else come across this issue?

Image of project

Run/Debug Configuration image

Project Structure image

If I hit Run(in toolbar)>Run you can see no available configurations

EDIT: added Main module to source and MainKt class is now available in Add Run/Debug Configuration, but I get the error in below image, "Error: Could not find or load main class MainKt Caused by: java.lang.ClassNotFoundException: MainKt"

Error: Cannot find MainKt

Will
  • 31
  • 2
  • just click the run button next to the main function in the kotlin file? – dan1st Oct 12 '21 at 11:18
  • There is no run button next to the function, but I know what you mean as it's been there in previous projects. – Will Oct 12 '21 at 11:46
  • Seems there is no MainKt class. Please try to remove existing run configuration and create new one. – y.bedrov Oct 12 '21 at 13:28
  • Hi, I've just started this project from new and there are no run configurations available to remove. I cannot find the MainKt.class. Should it always be there by default or does it depend on your project setup when you create it? – Will Oct 12 '21 at 21:43
  • Please share your project example. – y.bedrov Oct 17 '21 at 16:49

1 Answers1

1

The source for the class MainKt (main.kt) does not appear to be under your sources root (src/main/kotlin), it's one level up if I interpret the UI of intellij correctly. Try moving it into the kotlin/ directory.

somethingsomething
  • 1,746
  • 6
  • 8