Error could not find or load main class in Eclipse – 3 Ways to Fix

In this tutorial you will learn about the error could not find or load main class in eclipse and the ways that could solve this error.

When class loader is unable to load the main class of our application then this error will come. Many reasons are there for this has to be happen.

In case you are struggling to solve your program errors or need java assignment help then you can visit www.geeksprogramming.com.

Ways to Fix Error could not find or load main class in Eclipse

1. If Path is Incorrectly Specified

This error will come mainly due to this reason.

In eclipse if we run application Run as java program then eclipse will give default path as the User entries in class path in Run configurations. As shown below.

Error could not find or load main class in Eclipse 1

If we import the project from outside without default class path eclipse can’t find main class. Or else if any mistake is in user entry or Bootstrap entries in class path then also eclipse can’t find .class file of main class. Here our project will compile and all class files will be created in bin folder but path is not correctly specified. Here we can see .class file of main in bin.

Solution:

If user entry is deleted or any mistake then click on Restore Default Entries option in Run configurations -> class path. Then eclipse will restore the user entries. If default class path is not set then click on user entries -> Add projects -> select your project name -> click ok. Now run it. This problem won’t come now if problem comes because of wrong class path.

If because of bootstrap entries then Click on Bootstrap entries -> Advanced -> then select Add library -> JRE system library -> OK

Run it then it error will gone. 

2. Missing Libraries or Jars

This error may come due to missing libraries or jars. If any external library or jar file missed or moved to other location then no class file will be created in bin directory because it can’t be complied. Before project name red exclamation mark will appear. As shown below.

Error could not find or load main class in Eclipse 2

Solution:

To resolve this issue right click on project -> build path -> configure build path -> Libraries. Remove erroneous libraries with red marks. Add libraries again. See all the Run it Error may not come. And make sure that all dependent libraries should be there even if we are not using them.

Error could not find or load main class in Eclipse 3

3. If Metadata Corrupted

Meta data contains project preferences if metadata corrupted project cannot be build. No class file will be generated. Then also eclipse can’t find main class.

Solution:

Then delete .metadata folder.

Import the project again and run. Error will go.

Some Other Solutions for This Error

If any problem with bin folder clean the project. For cleaning option click on project -> clean. Actually cleaning means deleting all .class files which are residing in bin folder. If we recompile project then all .class files will again created in bin folder. Again run error may go. If not gone check bin folder after cleaning again if all the .class files are deleted or not. If not deleting then try this. If any problem with bin folder then it will help.

Manually delete the bin folder.

Now recompile the project. Again bin folder will be created with all .class files. Now run it error may go.

Sometimes our main class will be related to some other classes which are present in other libraries. But they are not in our class path. Then also eclipse will give us error could not find or load main class. For that we need to know where the error is located actually. Debug is better way to know about it. Debug will find the main class if it is unable to find then it will tell us in which class contains the error. Then solve that error.

I hope above solutions will fix Error could not find or load main class in Eclipse. If you have any queries you can ask in comment section below.

1 thought on “Error could not find or load main class in Eclipse – 3 Ways to Fix”

  1. Tried all of this.
    Classes gets generated in bin directory correctly. No errors in Jars imported.
    Performed Project -> Clean.
    But nothing seems to work.

    Using jdk1.8.0_102.

Leave a Comment

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