Eclipse“错误:找不到或加载主类” [英] Eclipse "Error: Could not find or load main class"

查看:137
本文介绍了Eclipse“错误:找不到或加载主类”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在笔记本上有一个eclipse项目,我推到Git https:// github.com/chrisbramm/LastFM-History-Graph.git



它完全在我的笔记本电脑上运行/构建而没有问题,但在我的桌面上没有Eclipse给出错误


错误:找不到或加载主类lastfmhistoryguis.InputPanel


我尝试从以下方式构建项目:

 项目>构建项目

但没有发生任何事情。即使在我的笔记本电脑上没有设置这个设置,我将这个电脑上的 PATH 变量设置为 JRE6,JRE7和JDK 1.7.0 。我有我的中的Jar文件( last.fm-bindings-0.1.1.jar )在我的笔记本电脑上的C:\Users\Chris\Downloads 文件夹中的.classpath 文件,因此它不包括在我最近带入的git树中项目文件夹和承诺,但我不知道我是否做到了正确。
这也可能是一个问题,但没有一个主要的参数。



我现在无法解决,我需要检查/更改。

解决方案

如果您使用创建一个java类public static void main(String [] args ),Eclipse将通过右键单击文件本身或项目资源管理器中的文件来运行该主要方法,然后选择:



< blockquote>

运行方式 - >Java应用程序。


一旦你这样做,Eclipse存储关于你的类的信息,所以你可以从运行方式菜单(工具栏上的绿色播放按钮)或运行配置对话框轻松地运行该类。



如果你随后移动java类(手动,或者),然后再次选择


运行方式 - >Java应用程序从新的位置,p>

,Eclipse将运行原始存储配置,尝试从其原始位置调用此类,这将导致此错误。



对于我来说,修复是去运行配置,(绿色播放按钮 - >运行配置)并删除对该类的所有引用。下次运行


运行方式 - >Java应用程序


Eclipse将为移动的类编写一个新配置,错误将消失。


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.

解决方案

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.

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.

这篇关于Eclipse“错误:找不到或加载主类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆