简体   繁体   中英

Simple "Hello World" Java program not working in Eclipse

I opened Eclipse, named the project "firstProject" and then made a class called 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)

What is the problem?

You should create your Apples.java in src folder of firstProject project. 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

2) I put the class Apples.java in the directory named firstProjject

3) I do not provide the package declaration in the class Apple which is : package firstProjject;

4) I try to run the class in spite of seeing compilation error. As a result I get following error from eclipse:

在此处输入图片说明

So now I think it is clear to you where lies the mistake. Please provide package declaration. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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