Online Course Discussion Forum

unable to run hello world in java

 
 
Picture of Jialin Wang
unable to run hello world in java
by Jialin Wang - Monday, 13 June 2022, 10:41 PM
 

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

 
Picture of Dr. Kevin Wang
Re: unable to run hello world in java
by Dr. Kevin Wang - Tuesday, 14 June 2022, 12:37 PM
 
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.

Picture of Jialin Wang
Re: unable to run hello world in java
by Jialin Wang - Tuesday, 14 June 2022, 6:00 PM
 

thank you, it works now!