I just created a kotlin project, and when trying t...
# getting-started
r
I just created a kotlin project, and when trying to run, it tells me
MainKt could not be found
. Creating
class MainKt { fun main() { ... } }
gives me a
duplicate class MainKt
🤔
s
when you use a first-class main-function in a main.kt file the generated jdk-bytecode will be equivalent to a public static void main function in a class called MainKt.
r
Doesn't seem to exist on run, had to manually make a
@JvmStatic
etc.
c
Your
Main.kt
file should contain:
Copy code
import ....

fun main() {
 // start code here
}
Clicking the run arrow next to the function should run everything fine, unless you changed something wierd in the gradle config
☝️ 1
g
You should never create classes like MainKt Classes with Kt suffix are generated for compiler for top level members (so functions, properties which are declared outside of an actual class) So if you have a file Main.kt with any top level function (like
main()
compiler will create class MainKt for it So looks that your config looks for
MainKt
class (this how it usually configured for Gradle), what you need to do is follow Chris' suggestion
r
Clicking the run arrow next to the function should run everything fine, unless you changed something wierd in the gradle config
Nah, got the error straight out of the gate
version
2025.1.3
g
what kind of error?
r
The
MainKt could not be found
Huh, can't reproduce with a new project
g
maybe your run configuration is incorrect, you can delete it first and add again