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

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

问题描述

我的笔记本电脑上有一个 eclipse 项目,我将其推送到 Git https://github.com/chrisbramm/LastFM-History-Graph.git

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

它在我的笔记本电脑上完全运行并且运行/构建没有问题,但在我的台式机上它没有 Eclipse 给出错误

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

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

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

我尝试从以下位置构建项目:

I've tried building the project from:

Project>Build Project

但是什么也没发生.我已将这台计算机上的 PATH 变量设置为 JRE6、JRE7 和 JDK 1.7.0,即使我的笔记本电脑上没有设置这些变量.

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.

我的 .classpath 文件中确实有 Jar 文件 (last.fm-bindings-0.1.1.jar),该文件位于 C:UsersChrisDownloads 文件夹在我的笔记本电脑上,因此它没有包含在我最近带入项目文件夹并提交的 git 树中,但我不确定我是否做得对.这是否也会引起问题,但其中没有主要论点.

I did have Jar file (last.fm-bindings-0.1.1.jar) that was in my .classpath file that was in C:UsersChrisDownloads 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.

推荐答案

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

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:

运行方式"->Java 应用程序".

"Run As" -> "Java Application."

执行此操作后,Eclipse 会存储有关您的类的信息,因此您可以从运行方式"菜单(工具栏上的绿色播放按钮)或运行配置"对话框轻松地再次运行该类.

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.

如果您随后 MOVE java 类(手动,或然而),则再次选择

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

运行方式"->Java 应用程序",

"Run As" -> "Java Application,"

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


解决方案:
对我来说,修复是转到运行配置(绿色播放按钮 -> 运行配置)并删除对类的所有引用.下次运行时

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

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

"Run As" -> "Java Application"

Eclipse 将为移动的类编写新的配置,错误就会消失.

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

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

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