I have just downloaded the IDE, and I want to edit my first Java file with it, I\'m not interested in creating a whole project, just editing the single file.
So I op
If you can't run your correct program and you try all other answers.Click on Edit Configuration and just do following steps-:
Sometimes, patience is key.
I had the same problem with a java project with big node_modules / .m2 directories.
The indexing was very long so I paused it and it prevented me from using Run Configurations.
So I waited for the indexing to finish and only then I was able to run my main class.
If you use Maven, you must to declare your source and test folder in project directory.
For these, click F4 on Intellij Idea and Open Project Structure. Select your project name on the left panel and Mark As your "Source" and "Test" directory.
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).
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) {
}
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:
Some of the classes in my folder don't have a main()
method, but I still see a Run option for those.