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:40

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.

查看更多
不再属于我。
3楼-- · 2019-01-02 18:41

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.
查看更多
梦醉为红颜
4楼-- · 2019-01-02 18:41

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.

查看更多
皆成旧梦
5楼-- · 2019-01-02 18:42

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.

查看更多
几人难应
6楼-- · 2019-01-02 18:42

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

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

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