Unable to run Java code with Intellij IDEA
right click on the "SRC folder", select "Mark directory as:, select "Resource Root".
Then Edit the run configuration. select Run, run, edit configuration, with the plus button add an application configuration, give it a name (could be any name), and in the main class write down the full name of the main java class for example, com.example.java.MaxValues.
you might also need to check file, project structure, project settings-project, give it a folder for the compiler output, preferably a separate folder, under the java folder,
Don't forget the String[] args
in your main method. Otherwise, there's no option to run your program:
public static void main(String[] args) {
}
Move your code inside of the src
folder. Once it's there, it'll be compiled on-the-fly every time it's saved.
IntelliJ only recognizes files in specific locations as part of the project - namely, anything inside of a blue folder is specifically considered to be source code.
Also - while I can't see all of your source code - be sure that it's proper Java syntax, with a class declared the same as the file and that it has a main
method (specifically public static void main(String[] args)
). IntelliJ won't run code without a main
method (rather, it can't - neither it nor Java would know where to start).
My classes contained a main()
method yet I was unable to see the Run option. That option was enabled once I marked a folder containing my class files as a source folder:
- Right click the folder containing your source
- Select Mark Directory as → Test Source Root
Some of the classes in my folder don't have a main()
method, but I still see a Run option for those.