Class not found in module warning when try to create Run/Debug Configuration in Intellij
Asked Answered
D

9

43

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.

Dagnah answered 30/8, 2018 at 7:29 Comment(1)
D
36

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.

Dagnah answered 2/9, 2018 at 20:26 Comment(3)
This happened to me while importing a scala maven project, and intellij was dumb to not recognise the App class.Souvenir
This 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.Ettaettari
Tks, after deleting .idea from my git repo, the project stopped compilling (of course...), by setting the 'Sources folder' under Modules, it worked againPreferable
M
77

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.

Maccaboy answered 4/5, 2020 at 20:18 Comment(2)
Thanks. It works for Rider debugging nodejs application too.Merridie
Thanks, now i cannot run the appFurring
D
36

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.

Dagnah answered 2/9, 2018 at 20:26 Comment(3)
This happened to me while importing a scala maven project, and intellij was dumb to not recognise the App class.Souvenir
This 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.Ettaettari
Tks, after deleting .idea from my git repo, the project stopped compilling (of course...), by setting the 'Sources folder' under Modules, it worked againPreferable
B
9

I'll explain a little bit more detailed version of the Accepted answer.

  1. Open Project structure window (Using Ctrl+Shift+Alt+S shortkey or From File -> Project structure option in the IDE menu)

  2. From there, select modules tab and remove the current configuration you have.

Project structure image

  1. Import module again.

Import module

  1. Select the root of your module (The old .iml file should be in that folder)

Select the right folder

  1. A dialog will popup. Select default options and finish.

  2. Apply the modifications by clicking OK.

Brezin answered 29/10, 2019 at 18:21 Comment(0)
T
4

I've struggled with the same problem on my Kotlin project. The solution that works for me:

  1. Right mouse click on src/main/kotlin/Main.kt
  2. "Override file type"
  3. Choose "Kotlin" file type in the "Override file type" menu
  4. In the "Run/Debug Configuration" set "Main Class" as "MainKt"
Torrence answered 14/1, 2022 at 0:18 Comment(2)
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.Fury
This is the best answer that solved my issue direct, no frills.Williemaewillies
D
2

My variant: Run -> Edit Configurations -> Configuration -> Environment -> Shorten Command Line Select "JAR Manifest".

Dasya answered 13/10, 2020 at 7:57 Comment(0)
V
1

i deleted .iml file and reimported the project using maven.

Venetian answered 5/7, 2021 at 12:56 Comment(0)
F
1

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

Flour answered 1/9, 2022 at 15:16 Comment(1)
Thanks, in version 2023.1 this options moved to "pom.xml" (right click) -> Maven -> Reload project. And it works!Palmirapalmistry
N
0

set working directory to module root directory or $MODULE_WORKING_DIR$ in Run/Debug configurations settings to help Intellij to find classes.

Nonsuch answered 30/8, 2018 at 7:35 Comment(0)
R
-1

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

Repurchase answered 13/3, 2022 at 18:36 Comment(1)
It doesn't work that way - if you have multiple files, you don't know what you're runningDicrotic

© 2022 - 2024 — McMap. All rights reserved.