# Could not find or load main class MainKt

**URL:** <https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453>\
**Category:** Support\
**Created:** [April 12, 2024, 11:56am UTC](https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453 "2024-04-12T11:56:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahsan.iftikhar.qureshi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ahsan.iftikhar.qureshi/32/10799_2.png) [@ahsan.iftikhar.qureshi](https://discuss.kotlinlang.org/u/ahsan.iftikhar.qureshi)\
**Post date:** [April 12, 2024, 11:56am UTC](https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453/1 "2024-04-12T11:56:00Z")

</div>

Dear Community,

By way of context I am a beginner in Kotlin and Intellij IDEA. Based on my online search, no matter what I do I am not able to resolve the following error. I have already explored many of the suggestions in StackOverflow and none seem to work.

Error: Could not find or load main class MainKt  
Caused by: java.lang.ClassNotFoundException: MainKt

I am using a Windows 11 laptop, where I don’t have the admin rights. I have installed Intellij IDEA using the Toolbox application.

May I kindly, request your support (kindly, do consider that I have already applied most of the answers on Stackover flow like rebuilding the project, reinstalling IntelliJ, etc.)

 ![kotlin2024-04-12_15-57](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/8/8db83e4b8762d48e799403c376281584f3bf30d5.png)  
 ![kotlin_12024-04-12_15-58](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/7/7c0970b84caf6bbb5679cdf8693c558c24381e78.png)

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [April 12, 2024, 12:34pm UTC](https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453/2 "2024-04-12T12:34:41Z")

</div>

I suggest using Gradle (or Maven) as otherwise it is hard to say what’s your project config exactly. According to the log, it seems you don’t at all load the code of your project when running it. It mentions stdlib and annotations.jar, but no classes from the project. Why? I have no idea - again, it depends on the setup of your project in IntelliJ.

---

<div class="post-metadata">

**Author:** ![ahsan.iftikhar.qureshi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ahsan.iftikhar.qureshi/32/10799_2.png) [@ahsan.iftikhar.qureshi](https://discuss.kotlinlang.org/u/ahsan.iftikhar.qureshi)\
**Post date:** [April 12, 2024, 11:15pm UTC](https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453/3 "2024-04-12T23:15:47Z")

</div>

Dear broot, Thanks for your input and explanation. Being a beginner I believe I will have to do some search and understand it better. Any good resource on properly setting up a project and trouble shooting with Gradle will be really helpful.  
Thanks again for your support.

---

<div class="post-metadata">

**Author:** ![Skater901](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/skater901/32/10163_2.png) [@Skater901](https://discuss.kotlinlang.org/u/Skater901)\
**Post date:** [April 14, 2024, 3:05am UTC](https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453/4 "2024-04-14T03:05:32Z")

</div>

You can use IntelliJ itself to create a new Gradle project; when you create a new project with IntelliJ, it gives you options for what kind of base project you want to create, so you can create a Kotlin-only project with no build tool, or you can create a Maven project using Kotlin, or a Gradle project using Kotlin, or even something else entirely.

---

<div class="post-metadata">

**Author:** ![phill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phill/32/8551_2.png) [@phill](https://discuss.kotlinlang.org/u/phill)\
**Post date:** [April 18, 2024, 3:06pm UTC](https://discuss.kotlinlang.org/t/could-not-find-or-load-main-class-mainkt/28453/5 "2024-04-18T15:06:25Z")

</div>

Or open a terminal in an empty directory and type  
`gradle init`

Choose 2: Application  
Choose 4: Kotlin  
Choose 1: dont split across multiple projects  
Choose your build script language. Groovy has more online answers, Kotlin is catching up  
Choose ‘no’ for new api (that’s what I do at least)  
Choose whatever test framework you want.  
Choose a project name (defaults to directory name)  
Choose a base package name (defaults to directory name)

You now have a kotlin project that you can run with  
`./gradlew run`

You can open this project in intellij if you wish.
