Eclipse找不到/加载主类 [英] Eclipse can't find / load main class

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

问题描述

我的Eclipse(靛蓝)运行正常。我创建了一个简单的类 Hello 。它位于文件夹 ch13 中的包 cont 中。但是,当我尝试从Eclipse运行它时,我从Java虚拟机启动器获取信息:

 找不到主类: cont.Hello。 

我试图从这个包运行其他类,它们运行正常(就是存在的类之前)。但是,在这个包中创建的任何新类都有这些问题。实际上,我在Eclipse中创建的任何新类都会遇到这个问题。我决定从命令行检查它的工作原理。似乎问题仍然存在 - 我得到相同的错误。我检查路径,它是 C:\Program Files\Java\jdk1.7.0_02\bin ,这是正确的(注意其他类正在运行Eclipse很好)。我试图运行与 java -cp。您好,并且出现一些错误,起始于 java.lang.NoClassDefFoundError:Hello(错误名称:cont / Hello)。代码本身很简单:

  package cont; 

public class Hello {
public static void main(String [] args){
System.out.println(Hello);
}

}

我如何解决它,我的类仍然在Eclipse下运行?

解决方案

.metadata 已损坏。



步骤:


  1. 停止eclipse,删除工作区中的.metadata并重新启动eclipse


  2. 导入项目


  3. 再次运行


PLS注意:使用此方法意味着您也将失去您的项目和插件。你必须重新设置这些。


My Eclipse (Indigo) was running just fine. I created a simple class Hello. It is placed in package cont in the folder ch13. However, when I try to run it from Eclipse I get info from Java Virtual Machine Launcher:

Could not find the main class: cont.Hello.  

I tried to run other classes from this package and they run just fine (that is the classes that existed there before). However any new class I create in this package has these problems. Actually any new class I create in Eclipse runs into this problems. I decided to check how it works from the command line. It seems that the problem still exist - I get same error. I checked the path and it is C:\Program Files\Java\jdk1.7.0_02\bin, which is correct (note the other classes are running from Eclipse just fine). I tried to run with java -cp . Hello and there are some Errors produced starting with java.lang.NoClassDefFoundError: Hello (wrong name: cont/Hello). Code itself is simple:

package cont;

public class Hello {
    public static void main(String[] args){
        System.out.println("Hello");
    }

}

How can I fix it so that my classes still run under Eclipse?

解决方案

.metadata is corrupted.

Steps:

  1. Stop eclipse, delete .metadata in workspace and restart eclipse

  2. Import Project

  3. Run again

PLS NOTE: Using this method means you will lose your projects and plugins as well. You will have to set these all over again.

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

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