PlainError

Error: Could not find or load main class com.example.Main

Last checked 2026-11-11 · 3 fixes · reviewed answer

TL;DRThis Java error means the Java runtime cannot locate or start the main class named com.example.Main, usually because the compiled class file is missing, in the wrong place, or the command to run it is incomplete.

Most likely cause: The Java source file was never compiled into a .class file

Try first: Check if the .class file exists

Likely causes

  1. The Java source file was never compiled into a .class filemost likely
  2. The classpath or current directory does not include the folder containing the compiled classmost likely
  3. The package name in the source code does not match the folder structure on diskpossible
  4. A typo in the class name or missing dependencies in the classpathless likely

How to fix it

Safest first: SafeChanges settingsDangerous
  1. Check if the .class file existsSafe

    Navigate to the folder that should contain the compiled class and look for Main.class inside a com/example subfolder.

  2. Run the program with an explicit classpathSafe

    Tell Java exactly where to find the class by including the current directory or build folder in the classpath.

    java -cp . com.example.Main
  3. Compile the source fileChanges settings

    From the project root folder, run the Java compiler on your source file so it produces the needed .class file.

    javac src/com/example/Main.java

If that didn't fix it

Check that the package declaration at the top of Main.java exactly matches the folder path (com.example).

When to see a technician

If the project uses a build tool like Maven or Gradle and the error continues, ask an experienced Java developer to review the project structure.

Quick answers

What does Error: Could not find or load main class com.example.Main mean?
This Java error means the Java runtime cannot locate or start the main class named com.example.Main, usually because the compiled class file is missing, in the wrong place, or the command to run it is incomplete.
What causes Error: Could not find or load main class com.example.Main?
The Java source file was never compiled into a .class file. (most likely) The classpath or current directory does not include the folder containing the compiled class. (most likely) The package name in the source code does not match the folder structure on disk. (possible) A typo in the class name or missing dependencies in the classpath. (less likely)
How do I fix Error: Could not find or load main class com.example.Main?
Try these in order, safest first: 1. Check if the .class file exists. 2. Run the program with an explicit classpath. 3. Compile the source file.
What if that didn't fix it?
Check that the package declaration at the top of Main.java exactly matches the folder path (com.example).
When should I see a technician?
If the project uses a build tool like Maven or Gradle and the error continues, ask an experienced Java developer to review the project structure.
Did this fix it? Report a problem

Related errors

All Coding errors →