Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not find or load main class in intelliJ IDE

This might help:

1) "Build" menu -> "Rebuild Project". Sometimes Intellij doesn't rewrite the classes because they already exist, this way you ask Intellij to rewrite everything.

2) "Run" menu -> "Edit configuration" -> delete the profile -> add back the profile ("Application" if it's a Java application), choose your main class from the "Main Class" dropdown menu.

3)"Build" menu -> "Rebuild Project".


If none of the above answers worked for you, just close your IntelliJ IDE and remove the IntelliJ IDE file and folder from the root of your project:

rm -rf .idea *.iml 

Then open the project with IntelliJ. It must work now.


For me the solution was to fix the output directory under project settings. Before I was using just "target" for the Project compiler output. Instead I updated it to have a full path e.g. D:\dev\sigplusjava2_68\target enter image description here


I had this problem and I tried everything under the sun that I could think of and on this site.

None of my Java classes were being picked up after I pulled from a remote branch. All the classes had red Js by their names in the Project Hierarchy, not blue Cs.

In the end, I tried to follow this tutorial and a few steps in tried something not described and fixed the issue: https://www.jetbrains.com/help/idea/creating-and-managing-modules.html

Here's what I did:

  1. Goto File | Project Structure, or press Crtl+Shift+Alt+S
  2. Select Modules under the Project Settings section.
  3. In the Sources tab click Sources on the 'Mark as:' line.
  4. Click the Apply button.

For some reason, all my classes then had blue C's.

Someone with a better understanding of how IntelliJ and/or IDE's might be able to explain the phenomenon, but all I know is now it can see all the classes and more importantly the main one, and run.