[Fix] Could not find or load main class error in Java

Reading time icon 3 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

Key notes

  • Could not find or load main class error usually appears when developing Java applications.
  • To fix the problem, you need to ensure that your class names are correct.
  • Also, you can also fix the issue by checking if your package names are correct.
  • If youโ€™re getting Could not find or load main class in Eclipse, check your class references.
could not find or load main class

Could not find or load main class in a programming error, and it usually appears when you write your applications in Java.

Fixing this issue might be hard, especially if you’re new to Java, but hopefully this guide should be able to help you with this problem.


How can I fix could not find or load main class?

1. Check the class name

check class name could not find or load main class
  1. Open your Java program and check how you spelled the class name.
  2. Look at the compiler to see if the class matches.
  3. The class name typed on the compiler has to be an exact matchย with what you typed in the program.

Note: The most common mistake is when you declare a class name in the wrong format when running it from the compiler.

Also, the correct command to run aย .classย file generated by the Java compiler is java <class filename> You don’t have to provide theย .classย extension: java HelloWorld.class.

This is is an obvious solution, but it might work if you’re getting Could not find or load main class in Eclipse.


2. Check the package name

check package name could not find or load main class
  1. Check the package name where you have included your class.
  2. Use the correct form to run the class: Java packagename.classname. In our example, it will be dto.HelloHP.
  3. In the compiler, run the class from the parent folder of the package and not from the folder where the class is.

Note: If your class is included in a package, then to run it you must provide its fully qualified name.

Also, when you create a package, you actually create a folder structure like C:\Java\classes\packagename\classname.java

After checking your code, the Could not find or load main class Java message should be gone.


3. Remove class references

code could not find or load main class
  1. Go to the Run configurations in Eclipse.
  2. Click the Green Play Button and select Run Configurations.
  3. Remove all references to the class.

If you go now to Run As and select Java application, Eclipse will write a new configuration for the class you moved. Therefore, it won’t display the error anymore.

These are some simple guidelines, and they should come in handy if you encounter Could not find or load main class in Eclipse.


Troubleshooting and debugging is an important part of any Java application you create. This guide provides you solutions for a common error you might meet while running a java class.

If you run it from a Linux terminal and encounter this error, the first two solutions will work for you too. Check the class name and the directory from where you run your program.

More about the topics: Programming tools and tips