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

Vlad Turiceanu
by Vlad Turiceanu
Editor-in-Chief
Affiliate Disclosure

  • 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
To fix various PC problems, we recommend Restoro PC Repair Tool: This software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. Fix PC issues and remove viruses now in 3 easy steps:
  1. Download Restoro PC Repair Tool that comes with Patented Technologies (patent available here).
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues affecting your computer's security and performance
  • Restoro has been downloaded by 0 readers this month.

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.

idee restoro Still having issues? Fix them with this tool:
  1. Download this PC Repair Tool rated Great on TrustPilot.com (download starts on this page).
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues with Patented Technologies (Exclusive Discount for our readers).
Restoro has been downloaded by 0 readers this month.
This article covers:Topics:

There are no comments yet. Please leave a comment

add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *