Eclipse “Error: Could not find or load main class”

2019-01-02 17:39发布

I have a project in eclipse on my laptop that I pushed to Git https://github.com/chrisbramm/LastFM-History-Graph.git

It works fully on my laptop and runs/builds without a problem but on my desktop it doesn't Eclipse gives the error

Error: Could not find or load the main class lastfmhistoryguis.InputPanel

I've tried building the project from:

Project>Build Project

But nothing happened. I've set the PATH variables on this computer to JRE6, JRE7 and JDK 1.7.0 even though these aren't set on my laptop.

I did have Jar file (last.fm-bindings-0.1.1.jar) that was in my .classpath file that was in C:\Users\Chris\Downloads folder on my laptop hence it wasn't included in the git tree which I recently brought into the project folder and committed ,but I'm not sure whether I have done it right. Would this also be causing a problem but there isn't a main argument in there.

I can't work out now, what I need to check/change.

30条回答
妖精总统
2楼-- · 2019-01-02 18:28

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.

查看更多
泛滥B
3楼-- · 2019-01-02 18:30

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.

查看更多
孤独总比滥情好
4楼-- · 2019-01-02 18:31

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.

查看更多
公子世无双
5楼-- · 2019-01-02 18:31

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.

查看更多
孤独寂梦人
6楼-- · 2019-01-02 18:31

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!

查看更多
与风俱净
7楼-- · 2019-01-02 18:31

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.
查看更多
登录 后发表回答