简体   繁体   English

简单的“Hello World”Java 程序在 Eclipse 中不起作用

[英]Simple "Hello World" Java program not working in Eclipse

I opened Eclipse, named the project "firstProject" and then made a class called Apples .我打开 Eclipse,将项目命名为“firstProject”,然后创建了一个名为Apples的类。 This is the code:这是代码:

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

I've got this error message:我收到此错误消息:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: at firstProjject.Apples.main(Apples.java:2)线程“main”中的异常java.lang.Error:未解决的编译问题:at firstProjject.Apples.main(Apples.java:2)

What is the problem?问题是什么?

You should create your Apples.java in src folder of firstProject project.您应该创建Apples.java在src文件夹firstProject项目。 I have written file as我已将文件写为

package firstProject;

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

}

It is printing required String.它正在打印所需的字符串。

I have reproduced your problem at my system:我已经在我的系统上重现了您的问题:

1) I create a package named firstProjject 1)我创建了一个名为firstProjject的包

2) I put the class Apples.java in the directory named firstProjject 2)我把类Apples.java放在名为firstProjject的目录中

3) I do not provide the package declaration in the class Apple which is : package firstProjject; 3) 我没有在Apple类中提供包声明,即: package firstProjject;

4) I try to run the class in spite of seeing compilation error. 4) 尽管看到编译错误,我还是尝试运行该类。 As a result I get following error from eclipse:结果我从 eclipse 中得到以下错误:

在此处输入图片说明

So now I think it is clear to you where lies the mistake.所以现在我认为你很清楚错误在哪里。 Please provide package declaration.请提供包裹声明。 Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM