Eclipse Error Could not find or load main class
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This Java error means the JVM did not find the compiled class it was told to run, or it found a class name that does not match the real package and output layout. In Eclipse, that usually points to one of a few concrete problems: a broken run configuration, a package mismatch, or a build output issue. The fix is to verify the class name and classpath step by step instead of treating it as a mysterious Eclipse failure.
Make Sure the Main Class and Package Actually Match
The class you run must match its package declaration and its filesystem location. A simple Java example looks like this.
If this file declares package com.example;, Eclipse expects it in the matching source folder path, and the run configuration should reference com.example.MyApp, not only MyApp.
A mismatch between the declared package and the actual project structure is one of the most common causes of the error.
Check the Run Configuration in Eclipse
Eclipse stores a run configuration that names the project and the main class. If that entry points to an old class, a renamed package, or the wrong project, the JVM starts with the wrong target.
The quickest fix is often:
- open
Run Configurations, - select the Java Application entry,
- verify the project name,
- verify the full main class name,
- or delete the run configuration and create it again.
This matters especially after refactoring packages or copying classes between projects.
Rebuild the Project Output
Sometimes the source file is correct but the compiled .class output is stale or missing. Eclipse may have auto-build disabled, or the output folder may be misconfigured.
A clean rebuild often resolves that classpath state.
The command-line example is useful because it isolates the problem. If the class runs from the terminal, your Java code is probably fine and the problem is in Eclipse configuration. If it fails there too, the package or build output is likely wrong.
Verify the Source Folder and Output Folder
In Eclipse, the Java Build Path defines which folders contain source code and where compiled classes are written. If the file sits outside the configured source folder, Eclipse may show the code but not compile it into the expected output tree.
That produces exactly the kind of “could not find or load main class” behavior that feels confusing because the file visibly exists in the project explorer.
The important question is not “does the source file exist”. It is “did Eclipse compile it into the runtime classpath using the correct package path”.
Watch for Typos and Case Sensitivity
Java class names are case-sensitive. So are package names on many file systems used in development and build pipelines. A small mismatch such as myapp versus MyApp or com.Example versus com.example can break class loading even when the names look visually similar.
This is especially easy to miss when switching between platforms or importing older projects.
External Libraries Usually Are Not the Cause
This specific error is about loading the main class itself, not about missing third-party dependencies later in startup. Do not jump to library management first. Confirm the main class, package, source folder, and run config before looking at anything else.
That order of operations saves time because the root cause is usually local and simple.
Common Pitfalls
- Running
MyAppwhen the real class name should becom.example.MyApp. - Refactoring packages without updating or recreating the Eclipse run configuration.
- Storing the file outside the configured Java source folder.
- Assuming the source file exists means the class was compiled into the runtime classpath.
- Missing a case mismatch in the package or class name.
Summary
- “Could not find or load main class” means the JVM could not locate the compiled entry class it was asked to run.
- In Eclipse, the common causes are package mismatch, stale run configuration, or build output problems.
- Verify the full class name, not only the short class name.
- Rebuild the project and check the source and output folder mapping.
- Isolate with a command-line
javacandjavatest if Eclipse behavior is still unclear.
Related reading
- Eclipse error The import XXX cannot be resolved
- Eclipse java debugging source not found
- Eclipse Optimize Imports to Include Static Imports
- Eclipse returns error message Java was started but returned exit code 1
- Eclipse hangs at the Android SDK Content Loader
- Eclipse scala.object cannot be resolved
- Eclipse showing Maven Configuration Problem Unknown
- Efficiency of Java Double Brace Initialization?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.