Trying to create a Run configuration in Intellij For a Java application and get a warning that Class not found in module and it doesn't create the Run configuration. This only happened once I added the project to BitBucket. Before that it ran fine.
-
1Please check http://stackoverflow.com/a/42660624/104891. – CrazyCoder Aug 30 '18 at 07:45
9 Answers
None of the above worked, I had to do:
File -> Invalidate Caches/ Restart
Upon restart it re-indexed all files and everything worked again as expected.

- 17,496
- 26
- 97
- 150

- 904
- 1
- 9
- 7
The way I fixed the problem was to remove the existing Content Root from the project and adding a new one. For some reason, it looks like it got corrupted.
File->Project Structure under Modules : then on the far right side of the screen where it says Add Content Root, remove the existing Content Root and add it back again pointing to the correct location.

- 5,214
- 21
- 65
- 94
-
This happened to me while importing a scala maven project, and intellij was dumb to not recognise the App class. – Yogesh Kumar Gupta Jun 19 '20 at 18:26
-
1This was still a working solution for me on IntelliJ IDEA 2020. I suspect this happened to my run configs after an IntelliJ minor version update. – Jim Tough Apr 07 '21 at 14:10
-
Tks, after deleting .idea from my git repo, the project stopped compilling (of course...), by setting the 'Sources folder' under Modules, it worked again – Girdacio Pereira Apr 25 '22 at 19:46
I'll explain a little bit more detailed version of the Accepted answer.
Open
Project structure
window (UsingCtrl+Shift+Alt+S
shortkey or FromFile -> Project structure
option in the IDE menu)From there, select
modules
tab and remove the current configuration you have.
- Import module again.
- Select the root of your module (The old
.iml
file should be in that folder)
A dialog will popup. Select default options and finish.
Apply the modifications by clicking OK.

- 16,677
- 10
- 70
- 117
I've struggled with the same problem on my Kotlin project. The solution that works for me:
- Right mouse click on src/main/kotlin/Main.kt
- "Override file type"
- Choose "Kotlin" file type in the "Override file type" menu
- In the "Run/Debug Configuration" set "Main Class" as "MainKt"

- 41
- 3
-
Thank you! I had the same problem. I created a new Kotlin project from the Kotlin/Gradle template and added my own main.kt file (called as such) but until I did what you suggested above, got the same error about not being able to find the class in my own module. – Marc Fearby Jan 09 '23 at 10:32
-
My variant: Run -> Edit Configurations -> Configuration -> Environment -> Shorten Command Line Select "JAR Manifest".

- 21
- 1
i solved it by right clicking on "pom.xml" -> add as maven project

- 11
- 1
-
Thanks, in version 2023.1 this options moved to "pom.xml" (right click) -> Maven -> Reload project. And it works! – Umy Apr 30 '23 at 10:00
set working directory to module root directory or $MODULE_WORKING_DIR$ in Run/Debug configurations settings to help Intellij to find classes.

- 323
- 1
- 11
i had this issue and i found out that the play button on the left side the function is the answer and it solved the error:))

- 1
- 1
-
It doesn't work that way - if you have multiple files, you don't know what you're running – ha9u63a7 Jun 03 '22 at 22:14