Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA is not recognizing my java files as runnable and instead wants to run the class files. Any ideas of how to fix?

Anytime I try to run a java file by clicking run, it instead tries to run the class file and thus gives a no main method error.

When I try to right click on a java file and run that, it doesn't recogize it as a file that is runable.

I am still able to run programs from the command prompt but I would prefer to be able to run them in IntelliJ.

This occurred after trying to create a Class path when using JSon Libraries.

Edit:

Normally it shows java files with this icon: enter image description here

But instead it's showing this icon for java files: enter image description here

I think the change in icon might have something to do with it.

Edit 2: the exact error I get is "C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe"...bunch of other program file locations

Error: Could not find or load main class sample.Main

Process finished with exit code 1

like image 774
my code made me suicidal Avatar asked Nov 08 '18 15:11

my code made me suicidal


People also ask

Why cant I press run on IntelliJ?

Try right-clicking within the file that contains a main method, and click "Run CLASSNAME. main()". That should generate a run configuration for the file that will let you use the green play button.


3 Answers

I had the same problem and found out that my src wasn't marked as Sources Root. To change this:

  • right-mouse click on your src
  • navigate to "Mark Directory As"
  • choose "Sources Root" It will now recognize your files correctly and your main classes will be able to run again

IntelliJ not recognizing my .java-files

Problem solved

like image 154
Paul Avatar answered Sep 27 '22 21:09

Paul


I had a similar problem.It wouldn't pick up ModlServer in any project.
(Not just limited to the one I had open).

I had to file -> Manage IDE Settings -> Restore Default Settings


enter image description here

Note: I lost all my live templates, fonts, etc so just a heads up.

like image 24
Braden Borman Avatar answered Sep 27 '22 21:09

Braden Borman


I restarted my computer and that somehow fixed it.

like image 28
my code made me suicidal Avatar answered Sep 27 '22 22:09

my code made me suicidal