Menu

Error: Could not find or load main class

If you are getting the error Error: Could not find or load main class when you try to run any java program in using eclipse then you could perform any of the following resolutions to fix the issue. If a single resolution doesn't work for you then perform the next solution which is given below.

1. Go to your project path for e.g. C:\Users\java\rashid\jorvee > open .classpath file and verify all the entries given in this file are actually exist in your system. Below is the sample file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>

<classpath>

 <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>

 <classpathentry kind="src" path="src"/>

 <classpathentry exported="true" kind="lib" path="C:/Users/java/rashid/java-json.jar/java-json.jar"/>

 <classpathentry kind="output" path="bin"/>

</classpath>

2. Go to run > run configuration > classpath> Select Project > Advance > select option add folder and select the bin folder where your .class file get stored.

3. There might be a possibility that there is no classpath set for java class files. Please go ahead and set classpath manually by executing the below command on cmd.
javac -cp . PackageName/*.java

4. In some cases we have found that Java build path is not set up for the project, or somehow it gets removed from the directory then go ahead and set your project classpath here. Add your project in the source tab and JRE in libraries tab.
Project > Properties > Java Build Path

No comments:

Post a Comment