IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException


-javaagent:/Applications/IntelliJ IDEA
/Applications/IntelliJ IDEA -Dfile.encoding=UTF-8 Scratch

Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld

Process finished with exit code 1
Class File:
public class HelloWorld {

    public static void main(String... args) {

As you can see the above class does not have any complication issues or syntax errors. There can be multiple reasons that you may get the error, below are some of the solutions that may work for you!

  • Make sure that the class name is correct.
  • Go to Menu: Build -> Re-Build Project.
  • Remove .idea directory from your project and restart IDE.
  • Go to Files: Invalidate Cache/ Restart...
  • Check your project has a out folder, if not create one, example: /Users/code2care/IdeaProjects/java-examples/out
  • Edit Build/Run Configurations and check if you have selected the correct Java class that has a main method.

Fixing Could not find or load main class error
Fixing Could not find or load main class error
Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.