Online Course Discussion Forum

unable to run hello world in java

 
 
WangJialin的头像
unable to run hello world in java
WangJialin - 2022年06月13日 Monday 22:41
 

i worked through the process here and created the hello world program. it worked fine but when i switched the file to a different name it didn't run successfully. Why did this happen?


https://drive.google.com/file/d/1GmnsUaxq0YYAnOvlJfHmRfokm5AKiflm/view?usp=sharing

 
WangDr. Kevin的头像
Re: unable to run hello world in java
WangDr. Kevin - 2022年06月14日 Tuesday 12:37
 
The error message says 'The declared package "" does not match the expected' ... there should be words after "the expected", but your next field "Resources" (which is HelloWorld.java) covers it up.  You can pull the Resources field to the right to reveal the full error message.  I am guessing the expected package name is "test".  So one fix could be adding a line "package test;" at the beginning of your Java file.

Since we are not talking about packages in Java in this class, we shouldn't need to worry about package.  Your source file HelloWorld.java can be placed directly under "src" directory, and there is no need for the "test" subdirectory.  That will make the package "default package" just like the one for your hello.java file.  In Eclipse, red crosses in the Package Explorer indicates the source file and directories that have errors.

That is what I can think of based on your screenshot.  The code itself in the source file is fine.

WangJialin的头像
Re: unable to run hello world in java
WangJialin - 2022年06月14日 Tuesday 18:00
 

thank you, it works now!