[java] Eclipse error "Could not find or load main class"

I know there are many duplicates of this question, but I have looked at them all, and none of them have solved the issue.

I am trying to run a class that has a main function. I have cleaned the project, checked the classpath for '.', added the bin folder to the classpath under run configurations. I'm not sure what else to try because the class is certainly in the source folder.

Could someone please help me with this issue?

package testIt;

public class MemoryVisualizerApp extends Application{

public static void main(String[] args) {
    launch(args);
}

//Setup the scene and launch with given properties
@Override
public void start(Stage primaryStage) throws IOException{
    Parent root = FXMLLoader.load(getClass().getResource("/MemoryVisualizer.fxml"));
    Scene scene = new Scene(root, 650, 300);
    //Set whether the screen should be re-sizable (possibly best size = default)
    primaryStage.setResizable(true);
    primaryStage.setMinHeight(300);
    primaryStage.setMinWidth(550);
    primaryStage.setTitle("Memory Usage");
    primaryStage.setScene(scene);
    scene.getStylesheets().add("testIt/MemoryVisualizer.css");
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() 
    {
        public void handle(WindowEvent e){
              /*Currently the threads continue running after window is closed. Looking for
              a way to stop the app threads when window closed without stopping the program.*/
        }
    });
    primaryStage.show();
    primaryStage.show();
}

}

This code is located within a package, withing the src folder. It utilizes some JavaFX files that arent shown but that shouldnt be an issue.

This is the error: Error: Could not find or load main class testIt.MemoryVisualizerApp

This question is related to java eclipse classpath main

The answer is


Well the following worked for me...

  1. Went into the project folder (inside workspace)
  2. Then, deleted the bin folder
  3. Then, Cleaned project / projects (in Eclipse)
  4. built/run from Eclipse.

Try to point the classpathentry output path in the .classpath file to target/classes The classpath file is located in the project folder. Edit it manually.

In my case, it was like this before:

classpathentry kind="output" path="bin"

I changed it to:

classpathentry kind="output" path="target/classes"


Try also renaming the package before changing the configuration or reinstalling.
I got this weird error without having changed anything else than a few lines of code. Rebuilding did not work, Eclipse would not re-create the class even though the bin folder was empty. After renaming the package from test to test1 Eclipse started rebuilding and everything was fine.


This happened to me. I noticed that someone said I have to create an entire new WORKSHOP! Why? Because I installed a newer JRE version and that won't allow other previous versions to run on it. So all those old files I have become useless in a way. Not really, Just copy and paste it to new class and change it to an unused class name.


If all the solution does not work for you, it may be caused by missing libraries:

  1. Right click your project, Build Path --> Configure Build Path --> Java Build Path --> Libraries
  2. Remove the missing libraries
  3. Go to your main class and run it

What I ended up doing is in Eclipse, copy the entire project and paste it again (and give it a different name of course). Then run your copied project. It should ask if you want it to run as a Java Applet or as a Java Application. Click on Java Application and it should work again. Then you can remove the original project and rename your current project to its original name if you wish.


I faced the similar problem, a workaround is to open up a terminal, go to project folder and run

java cp target/<your_jar_artifact.jar> <com.your_package.YourMainClass>

I have checked all possible solutions including re-installation of JDK, eclipse as it worked for many people but unfortunately it didn't work for me. Also updated main class in pom.xml but it didn't help. It took my sleep away. I was trying different options and suddenly the magic happened when I checked this checkbox. It might be helpful for many people so thought of sharing enter image description here


I had the same problem. Spent few hours and finally changed my workspace back to local folder and everything works now. Maybe saves some time for others. Jon


If your code is good and you know you're having an Eclipse problem, this will solve it.

You could simply delete $yourproject/.classpath , $yourproject/.project , and $yourworkspace/.metadata. Someone else mentioned this option. It will blow up your entire workspace though. Instead:

  1. Delete .classpath and .project from your project
  2. Delete your project in eclipse. DO NOT check delete project contents on disk.
  3. Now, in a file explorer, go into $yourworkspace/.metadata.
  4. Search for $yourprojectname
  5. Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
  6. In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
  7. Right click your project > properties > Java Build Path > Source tab
  8. Select all source folders, remove.
  9. Add folder, select src (whatever your src folder is called) and add it
  10. Go to libraries tab
  11. Add any jars to your build path here. There should be no more errors on your project now.
  12. Run your project like you normally would.

I just had this problem after first having the problem of Windows 8 refusing to update my path no matter what I set JAVA_HOME to - java -version reported the last JDK instead of the one I stored in JAVA_HOME. I finally got that to work by putting '%JAVA_HOME%/bin;' at the front of the path environment variable instead of at the end. Then I launched Eclipse and all the sudden it could not find my main class when it worked fine before this. What I did to fix it was went into the project properties, removed the existing JRE library from the libraries tab, added a new JRE by selecting the "Add Library" button and then followed the prompts to install JRE 7 as my default JRE. Now all is back to working.


In your Eclipse Preferences -> java -> Installed JREs -> Select the Java SE the jdk which you have on your machine and add the JDK


I was getting the same message and I solve the problem moving out two dependencies from my pom.xml called "org.slf4j". After that It worked perfectly!


I faced similar problem in my maven webapp project after spending nearly one hour , I found a solution which worked for me .I typed the following maven command and It worked

mvn clean install -U
I dont know the exact reason behind it.


I had the same issue and I could not start any project with main() methods.

I tried almost everything mentioned above, but it turned out that I had a little mistake in my pom.xml file.

You can check this file too!


this could cause of jdk libraries if you had imported into jre

this happen to me , so check installed jre jars

in eclipse click on Windows > Preferences > Java > Installed Jres > click on Jre and edit after that look into jar list make sure none is of jdk or corrupted , enter image description here


In your classpath you're using an absolute path but you've moved the project onto a new machine with quite possibly a different file structure.

In your classpath you should therefore (and probably in general if you're gonna bundle JARS with your project), use relative pathing:

In your .classpath change

<classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/><classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/>

to

<classpathentry kind="lib" path="last.fm-bindings-0.1.1.jar"/>

Mostly this happens, because Eclipse cleans the .class files, but don't build them again. Check the bin folder, it should be empty. Then you should check, is there anything else, which is causing build ti fail. You might have added some jars in classpath, which Eclipse might not be able to find.


The same error I am facing in my eclipse and going through above all did not help me out, So here are the steps you can do:

  1. Check the problems- Windows->Show view->others->problem if you find something their errors saying "A cycle was detected in the build path of project xxx - Build Path Problem". then Do simple thing: Mark Circular dependency as a warning: Windows -> Preferences -> Java-> Compiler -> Building -> Circular Dependencies and it will fix your problem. Never forget to clean the project after that: Project->clean

Hope this will help!


I had the same problem. In my case I did the following, to resolve it.

  1. Select the project in the Eclipse IDE, right click, and open properties dialog.
  2. Select "Java Build Path" item on the left panel of the Properties dialog.
  3. Select the "Libraries" tab, on the right hand panel.
  4. Remove the libraries (jars), which are marked red, or fix the path.
  5. Save the Properties dialog. After removing the "Not found" libraries, Eclipse run/debug started working. The "Not found" message would also show up in the "Problems" pane. which you can open using, Window->Show View->Problems, command sequence. This pane gives you useful messages. The same message might show up for many reasons, other than what I encountered.

Observation: The classes directory in my case was not created, which means that the javac failed. On command line also, javac works the same way, if you have multiple java files in the same invocation of javac, and one java file encounters a problem, then no class files are created.

Which means Eclipse puts all the java files in the project with single invocation of javac.

Now if there are no class files generated, obviously, the message now makes sense. The compile errors are also shown in the "Problems" pane.

Now this would be the case if there is a compile error. If just a jar file which is not used at all, is on the classpath, there should not be any problem.

Even if my project had problems, I ignored it, because I was just testing a single class, and was thinking that only that file would get compiled and run, because it was a standalone test, without any dependencies.

But that is not the case with Eclipse. I wish they did it that way. As you can see lot of people got burnt this way.

Thanks


I had similar problem, my standalone java program was not working. I had other compilation error in my workspace in other unrelated java files. After removing all compilation errors I could run my standalone java program.


Try to check first in the Problems window the errors you have. It is most likely it. Then check in the Configure Build Path... window under Order and Export for errors in jars and libraries (missing, duplicates, etc.).

Fixing the problems will fix the class-loading issue.


I ran into the same error today, I refactored my project name and then refactored it back to the old name and it ran just fine after that.


I too faced this issue today. Whatever new class I created with main method i faced the same issue. Then I checked the build path and saw that one of the java api jar file - nashorn was showing as missing. I put it back in the ext folder and it worked!


I had this same problem with Eclipse-Mars. I had a working project then put it in my Git repository. That broke the execution (I guess because the actual Java files got moved to the git location and no longer existed in my workspace). I did a Maven>Update and it now works.


Project files using a custom archive in the build path, to fix -> go into the class path file, find and remove the entry then collect a new copy of the archive and add it to the build path again. You'll need to rebuild the project and to check the "run configurations" after.


Check that your project has a builder by either:

  • check project properties (in the "package explorer", right click on the project, select "properties"), there the second section is "Builders", and it should hold the default "Java Builder"
  • or look in the ".project" file (in .../workspace/yourProjectName/.project) the section "buildSpec" should not be empty.

There must be other ways, but what I did was:

  • shut down eclipse
  • edit the ."project" file to add the "buildSpec" section
  • restart eclipse

A proper minimal java ".project" file should look like:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>myProjectName</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>       
                    <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>      
</projectDescription>

Found This while searching, and it was after I updated my Java that the problem seemed to occur.

In Eclipse from your project:

Right-click on your project
Click Properties
Java build path: Libraries; Remove the "JRE System Library[J2SE 1.4]"
Click Add Library -> JRE System Library
Select the new "Execution Environment" or Workspace default JRE

Happened to me when I changed installed JREs to JDK7 instead of JRE7. Everything compiled but I couldn't run anything from Eclipse "eclipse-error-could-not-find-or-load-main-class"

Fix; going back to previous JRE7.


I ran into this error today because I set up a hello world program and then cut and pasted a new program into the same file. To fix the problem of not finding hello world as the last was called I clicked Run-> Run Configurations and then under Main Class I clicked search and it found my new class name and replaced it with the correct new name in the text that I pasted. This is a newbie problem I know but it is also easy to fix. I hope this helps someone! Douglas


To solve this error do the following steps:

Step 1: Open the .project file.

Step 2: Check two tags...

    a) <buildSpec>

    b) <natures>

Step 3: If the above-mentioned tags do not include any content then surely the above error is going to occur.

Step 4: Add the following content to each tag in order to resolve the above error.

For <buildSpec> :

<buildSpec>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>

For <natures> :

<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
</natures>

Step 5: Save your file by hitting ctrl + s.

Step 6: For safe side just close the project once and reopen it.

Step 7: That's it. You are ready to rock!!!

Please mention in comments if the solution was helpful.

Thank you.


My Main class could not be found or loaded problem is caused by an interesting reason.

In our project, we are using Maven as build tool and my main class extends a class, which is on the class path but its scope was test, while the main class is not under the test package.

If your main class extends a class, first try to run your main class by removing extends part. If it runs, you will at least understand that the problem is not because of run configuration or eclipse but the class, your main class extends.


I had this error. It was because I had static void main(String[] args)
instead of public static void main(String[] args)

I spent nearly an hour trying to figure that out.

Note: The only difference is that I didn't declare main to be public


Check if you have included any missing dependencies. In my case I've imported json jar (which is no longer present in that path). Removing it from Libraries helped.

Libraries

To navigate to Libraries (Right click on project -> Properties).


I had the same problem after I created new package("tables") in my project.

I went to Window -> Show View -> General -> Error Log and Ive read error:

JavaBuilder handling ImageBuilderInternalException while building: PizzaService

org.eclipse.core.internal.resources.ResourceException: Resource '/PizzaService/bin/tables' already exists.

as it turned out I had a text file in another source folder with the same name as this new package. So I've changed text file name from "Tables" to "Tabless" and I could run my project again.

Hope this helps.


Similar thing happened to me few times, the only way I knew to fix this was to remove the metadata folder. Fortunately I have found another way.

Try going to project properties > Java Build Path > Order And Export tab > select all (or try to play with check boxes there).

This should cause complete project rebuild and Eclipse to see main class.

Addition: I have noticed that this bug occurs when you have many projects in a work space and some of them is configured wrong(red exclamation mark appears). Fixing project build path and other settings(even if this project is not related to the one you have problems with) should fix an issue.


This just happened to me today after updating my JRE. I cleaned the project and it started working again.

Project -> Clean will remove any existing class files and completely rebuild the project. There's more information on Eclipse's clean function here.


If You are using eclipse then the following steps will solve your problem:

Go to Run -> Run Configurations -> Main Class Search -> Locate your class manually -> Apply -> Run


This problem occurred for me when I deleted a ".jar" file from Eclipse project by right clicking on it and hitting "delete" (not from "Build path").

To solve, I tried the following steps:

1- Right click on the project

2- Build Path --> Configure Build Path

3- Libraries

4- Delete the jar file from there (I see a red mark beside it).

I hope it is useful.


I recieved this error aswell, just after moving some resources. Checking the error log, I saw that Eclipse couldn't make a build since it couldn't remove a file/folder. Try manually removing the "bin" (or whatever it's called for you) folder.

That did the trick for me, at least.


I was having the same problem. I was having a maven project. According to my knowledge, it was because i had cleaned the project and there were no class files generated. I did mvn compile and it was started running.


I am assuming that you had imported the project into your desktop eclipse installation? If that is the case, you should just select Project > Clean. Then rebuild your project. Worked like a charm for me.


I spent tenths of hours trying to solve this, and what only helped me at the end was to notice that I had in my packages some files (text files) with the same name, like TODO, README and IMPORTANT. I went through every package of my project renaming those files (like TODO_packagename1, TODO_packagename2...) and when finished, I closed Eclipse and restarted it again. Then worked!


I had the same issue and solved it using:

Eclipse Mars
Egit
Github
Maven Project

The Problem was that i made my maven project available to github. It moved my project to my github folder.

Solution:

  • Close Eclipse
  • Delete the metadata folder inside your workspace
  • Restart Eclipse

Start screen will be displayed.

  • Close the start screen
  • Rightclick into package explorer
  • Chose "import maven project",
  • Navigate to your github folder and import the maven project.

After this my project compiled with success.


i had same problem but in my case firewall was blocking java directory path, make sure system firewall is allowing java directory path access.


I run into the same problem, but in my case it was caused by missing (empty) source folder (it exists in original project, but not in GIT repository because it's empty).

After creating the missing folder everything works.


that's because you guys created the class one time with the main method & after that may be you have been deleted that form or workplace & still some of the files exist ,i will suggest you to create that form or workspace again & then delete it by clicking on it completely,then after that if you created the some class like Runner class try to run it again.


I too faced same problem.

Simple solution is : delete project( not source files please). close eclipse--> go to project folder-- > remove classpath and project file .

then open Eclipse and create project in same location


if your package name is same with your class name this problem will occur.


Same Problem occur with me.I went to Project > Properties > Java BuildPath.

There In order of export , I moved up my java/main to the top priority.


I deleted a jar file from the bin directory. Right click on your project - Properties then Libraries tab. There was a red flag in there. I removed the jar file from the Libraries and it worked.


Sometimes, it might have a very simple solution

You have perhaps added a new version of the existing .jar file and forgot to remove the old version of the same .jar file.

Now try removing the old jar files (that are marked in red) in the Build Path > Configure Build Path


If you are using maven Project...

First please clean your project. then installed maven- if build success then run your project.

then project will be working fine.

thanks


Rebuilding using the command line has fixed this issue for me multiple times. For example, running ant build (for an Ant project) or mvn build (for a Maven project) will fix eclipse once it succeeds.


2 types of solutions exits for the same.

(1) Go to run configurations: - run->run configurations In the Classpath tab:

Select Advanced Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.

(2) If first solution is not working then it means the jar you are pointing out to your project is taking the path of your local Maven repo which is not getting updated to your project so better you check the jar from that local maven repo and copy it paste it into new project simply or just download it from any site and configure it into your build path.

I hope it helps.


Check the workspace error log (Windows-> Show View -> Error log). If you see any of the jar's imported is corrupted, remove the corresponding repository folder and re-import again.


Follow The Steps it Works for me : 1.Remove Configure build path from eclipse(Build Path) 2.Refresh 3.add configure Build Path->Source->add Folder->check src ok.


Just go to your Package Explorer and press F5, or for some laptops fn+F5. The reason is that eclipse thinks that the files are somewhere, but the files are actually somewhere else. By refreshing it, you put them both on the same page. Don't worry, you won't lose anything, but if you want to be extra careful, just back up the files from your java projects folder to somewhere safe.


I had the same problem with correct .classpath file, and soon found actually it's not the .classpath file counted (after I fixed this issue, I replace the workable .classpath file with the original one, the project still worked, which means the .classpath file was not the case)

Since it's a Maven project, all I did is:

  1. mvn eclipse:clean
  2. delete eclipse project
  3. import the project
  4. done

hope it helps!


I found other solution in my case this problem: Eclipse->Preferences->Java->Installed JRE then press button Search. Select folder in Linux /usr then Eclipse found all JVM.

Select another JVM too current. It is solved for my case.


If you are facing similar problem,it has to do with the "Run Configurations" not working properly in Eclipse.

error1

Please right clik on your java class containing the main method .Go to Run As-> Run Configurations and put the correct patrameters.Project should be the Project which contains the main class and Main class should be fuly qualified class name.See the snapshots below for clarity.It should wok fine then.Basically,you are creating a Run configuration and you can use that saved configuration for later use also.

selecting run configurationparameters to be entered correctly


This problem is also caused when you have special characters in your workspace path. I had my workspace in my personal folder and its name was in Greek, so it didn't work. I changed my workspace, now contains only english characters in its path, and now the project is built without any problems.


I also had the same issue and was getting "Error: Could not find or load main class ...."

I solved it as follows:

  1. Right clicked on my Java main class > Run As > Run Configurations.

  2. In the resultant popup box and Under Java Application your java file name would be selected mode... if not select it

  3. On the right side of the same box and under Classpath tab Clear all Bootstrap and User Entries (if any)
  4. Under Bootstrap Entries Click Advanced Button > Select Add Library Radio and click OK. In next "Add Library" box Select JRE System Library and provide your correct JRE location and click Finish. (If it is not visible then u have to add it by clicking Installed JRE > Add button). Now you can see JRE System Library under BootStrap Entries

  5. Next User Entries > Click Add Projects Button > And then under Project Selection box check on your Project name > OK

The main java file should now work. Hope this may help someone who would be facing similar issues.


I was running through the similar problems in my small java snippet

Here is what I did.

  1. I copied all the content in the Main class.

  2. Deleted the Main class Greeter.

  3. Right click -> Created a new Java class with name Greeter

    a> checked include main method when creating class

  4. voila !!! I was able to run as Java application by right clicking on the main class Greeter.java.

Just out of curiosity I again tried deleting the Greeter class and creating new class without checking main method, and it did not show me run as Java application option in right click.


you should add bin folder - run->run Configuration tab classpath advanced button - add folder - choose bin folder (yourproyect/bin)


I did all the things mentioned above, but none of them worked for me

My problem resolved as follows:

  1. Right click on your Project > Properties > JavaBuildPath > Libraries.
  2. Remove the jar file, having a red flag on it.
  3. If problem persists try the solution below. This worked for me when I faced this problem second time:
    1. Right-Click Project > Properties > Java Build Path > Libraries
    2. Remove Library
    3. Add Library. (Choose the JRE System Library )

I came across the same problem. You might get this error in many situations like below.

  • Some dependency problem in your pom.xml
  • The run configuration may not have proper configuration. You might want to delete the existing one and create the new one like suggested in other answers.
  • You may want to try like mvn clean, mvn build and other options.
  • You may want to delete the project and import it again.
  • You may want to restart Eclipse and check your luck if it works.

Here, the list of hit and trial goes on. Believe me the tool Eclipse is not that stupid. It is quite smart to find errors even at compile time. I tried all ways mentioned above, but none worked for me.

The main problem which worked for me was JRE version which was somehow got set to default (JRE System Library [jre1.5]). I reset it to jre1.8.* which I had installed in my machine.

I don't commit that this is only the solution to this problem but yes this could be one of the solution. So keep an eye on JRE version.


I was using eclipse oxygen and the problem persists everytime. Later i found that if your Eclipse workspace is under the directory with non ascii characters then somehow javaw.exe couldn't reach the bin directory. Suppose your directory name is Work_Hello the remove underscore sign and clean the project and run configurations. This worked for me. Reference: https://www.eclipse.org/forums/index.php/t/1093209/


I faced the same error, the error was in one of the imported external jars. After removing that jar project worked for me.


Rename the class with Ctrl+Shift+R (Windows), it will change name of the class everywhere where it is referred, and then do the opposite procedure. In my case it was caused by identical class names in several projects within the environment and Eclipse had hard time to understand which is which.


Actually I found the real Root Cause for this issue, by going to add each .jar files manually one by one, because the following answer within the same thread, suggests you to do so.

Cause:
You know as we are humans, we are really lazy creatures and that's why we have an option to "Select All" and also shortcut keys to perform that. So when I have to add around 30+ jar files for a PDF generation required app, I did go in this way,

Right Click on Project -> Properties -> Java Build Path

  • selected "Libraries" tab in it, then Add JARs...", browsed through the directories tree and (my JARs and the licence.txt files was in projects "lib" folder) within the "lib" folder, I selected All the files and Added. Can you guess what has been the wrong? It had successfully add all the files within the "lib" folder. But eclipse keeps trying to profess any of the text files you may have added as JAR file, in this way. So it can't build the links. This is the case.

So you have two options:

  1. Select only the JAR files wherever you want and don't be too lazy to add text and other types of files. or,

  2. Select all files within a specific folder where you wanna add JARs from, and then remove one by one, which are non-JAR files.

Note:
If you have added any of non-JAR files to the project in that way as you were trying to add "libraries", it will show you something like the following:

enter image description here

and keep trying to compile and at the end, it will give you the following error:

Error: Could not find or load the main class er.waterapp.some.MainFileGivenByConfigaration

  • MainFileGivenByConfigaration could be any class which you might have selected from Configuration to be take as the starting point of the app.

So this is it!!! Hope I may have had the chance to help some one out there and also save him a lot of time. :-)

Cheers,
Randika


I just encountered the same problem as yours and I followed Kumar's directions and it worked out. One thing to add: you need to make sure that after you go to the correct main class, check the "Classpath" and your project name should be existed under the "User Entries". If not, add your project to the directory then you're good to go.


I had a very strange reason for this error. Some of the files referenced in the local Maven repository (~/.m2/...) were corrupt. After deleting these and then rebuilding the application, it worked. Using a newer version of Maven exposed the corrupt files.


It seems that the class is not compiled by Eclipse.

Few pointers could be-

  1. Check if the .class file exists in your output folder.To know your output folder Right Click on Project->Properties->Java Build Path(Check at bottom).
  2. Check if Project->build Automatically is checked in the menu.
  3. Check if the HelloWorld class is in src folder or not.Right Click on Project->Properties->Java Build Path(Check source tab).

tl;dr: Clean your entire Build Path and everything you ever added to it manually. This includes additional sources, Projects, Libraries.

  • Project -> Clean
  • Make sure Project -> Build automatically is active
  • Project -> Properties -> Java Build Path -> Libraries: Remove any external libs you have ever added. Don't remove standard libraries like the JRE System Library.
  • Try to run your main class now. The "class could not be found / load" error should be gone. Try adding your external libs/jars one after each other.

Reason behind this: The compiler had issues linking the libraries to the project. It failed and produced a wrong error message.

In my case, it should have been something like "Could not add AutoHotkey.dll to the build path" because that was what made the compiler fail.


If this is still not working, have a look at the built-in ErrorLog of Eclipse:

Window -> Show View -> General -> Error Log


I followed several of the less drastic suggestion here to no avail. Then it dawned on me that Eclipse was confused because I had made a backup copy of my src project folder. (It was compiling all these "copy of" folders' *.java files and I noticed the subfolders for them in my bin folder.) I moved the backup elsewhere, got rid of the extraneous class files, did a Project > Clean, and everything was back to normal.


A very simple fix coul’d be delete a commented error in the pom.xml.

I don’t now why, but the error coul’d persist in the pom, even if you comment it. In my case, it was an innecesary scope tag for mockit or whole dependency of mockit, all commented!!! It was sufficent delete the commented lines and save the pom.


Usually cleaning and rebuilding the project from Eclipse does the trick.

However, when using Maven I have discovered times this does not work and I've noticed the 'target' folder of my maven project does not have anything under it. Running 'mvn clean install' from the command line and refreshing the project in eclipse does the trick.


For me, the reason that this error started showing up was due to classpath getting over the limit on windows. Then I discovered the option "Use temporary JAR to specify classpath (to avoid classpath length limitations)". Selecting this option fixed the problem for me. The option resides in Run/Debug Configuration, Classpath tab, see the image below.

enter image description here


Removing the JRE System Library and adding the default one worked for me.


I just ran into that problem. The cause... not sure. However, only happened after I added a new jvm. My solution:

  • went to run configurations: - run->run configurations

In the Classpath tab:

  • Select Advanced
  • Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.

I hope it helps someone out there. It took me time to figure this out.


Had the same problem, struggling with it for a while: couldn't find main class.

I did Project -> Clean -> Clean all Projects

Cleaned everything, and tada, it compiled!


Follow these steps :

1)Delete your current run configuration. 2)Go to the main class and run it by right clicking the mouse-->Run As-->Java Application.

Then you will see an auto generated new run configuration.


If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:

"Run As" -> "Java Application."

Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.

If you subsequently MOVE the java class (manually, or however), then again choose

"Run As" -> "Java Application,"

from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.


SOLUTION:
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run

"Run As" -> "Java Application"

Eclipse will write a new configuration for the moved class, and the error will go away.


I was also getting same message.That is due to the workspace problem.Create one new workspace and try there once. I think it will works.


These are the simple steps, which helped me to solve this problem.

  1. Close the eclipse
  2. Delete ".metadata" folder in your work-space. (may be hidden folder)
  3. Open the eclipse (it will automatically create ".metadata" folder in your work- space)
  4. Try to run the program.

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to classpath

spark submit add multiple jars in classpath How to resolve this JNI error when trying to run LWJGL "Hello World"? Intellij Cannot resolve symbol on import Eclipse error "Could not find or load main class" "Could not find or load main class" Error while running java program using cmd prompt Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger getting JRE system library unbound error in build path Run a JAR file from the command line and specify classpath How do I resolve ClassNotFoundException? File inside jar is not visible for spring

Examples related to main

String method cannot be found in a main class method How to access global variables Maven Error: Could not find or load main class Eclipse error "Could not find or load main class" Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args) What does "Could not find or load main class" mean? C# importing class into another class doesn't work In Python, can I call the main() of an imported module? Can there exist two main methods in a Java program? Could not find or load main class with a Jar File