How to Fix “Error: Could Not Find Or Load Main Class” [On Eclipse]

Eclipse is one of the leading platforms for executing Java program codes. However, lately many of the Eclipse users are encountering an error which comes with the message: ‘error: could not find or load main class’. The error occurs because Eclipse can’t run the program as it couldn’t find or load the main class.

You may try a quick fix to this annoying pop-up. You can debug the snippets of code. Just right-click on the Run option and select the option ‘Debug as Java Program’. This simple hack relieved many users from this error.

Fixes to Error: Could Not Find Or Load Main Class on Eclipse

If you are still struggling with the error then here you can get technical fixes to resolve it. There are various reasons behind this ‘error: could not find or load main class’. Hence, you will have to try different solutions to eradicate the error.

Fix 1: Specify the File Path

This error mainly occurs due to not specifying or mistakenly specifying the file path. If you are trying to run an application as a Java program then this error is one of the most common occurrences on the Eclipse platform. Let’s see how you can get rid of this mistake.

  • If the user entries are not present, then navigate the following path. Run Configuratrions> Class Path> Restore Default Entries. It will reset the classpath on Eclipse.
  • If you haven’t set the default classpath then consider the following steps. Choose the User Entries option.
  • Then continue to the Add Projects option. Opt for the ‘Select your project name’ option.
  • Click on the Ok button.

Specify the File Path

Check if the error persists whenever you run the program. If yes, then you have to rectify the Bootstrap entries. 

  • Choose Bootstrap Entries. Next, select the Advanced option.
  • Go to the ‘Add Library’ section.
  • Enter ‘JRE system library’. Finish the task by clicking on the Ok button.

Hopefully, the error will get resolved now.

Fix 2: Remove Problematic Libraries

You need to apply this fix when Eclipse can’t find some libraries or JAR files. They go missing from the Eclipse and you can notice a red mark before their names.

Here’s how you can fix this.

  • You have to right-click on the project that creates menace.
  • Choose the ‘Configure build path’ option.
  • Proceed to Libraries. 
  • Check those Libraries that have red marks before them. Remove those Libraries.
  • Add those Libraries again after a while.

Check if the error persists anymore by running the Java project again.

Fix 3: Delete Metadata 

This error can occur if the Metadata gets corrupted. Metadata consists of the project preferences. If it gets corrupted then the main class may face loading problems while running. 

  • Delete or remove the Metadata folder.
  • Next, you may import the project. 
  • Run the project and check whether the error message appears again.

Hopefully, the fixes were enough to get rid of the error: could not find or load main class

If the error is persistent, then go to the Project. Choose the Clean option. All the deleted class folders reside in the Bin folder. Delete the Bin folder. Now, again try to import and run that same project on Eclipse. Hopefully, the error will disappear now.

Maria Colombo
Maria Colombo
Articles: 1200