Problem with Eclipse - the declared package "" does not match the expected package
I've been trying to learn Java with this tutorial Java Video Tutorial - YouTube but the problem I have with it is that when he started recording, he already had his eclipse set up and started project with file already in it.
Now everytime I try to do what he does, I get the error the declared package "" does not match the expected package.
This is what I do:
Start Eclipse, new workspace in Eclipse folder,E:\Eclipse\workspace File>New>Java Project enter>use default JRE (currently jre7),name "Test" press Finish
Expand Test>right click on src>New package>name package defaultPackage in source folder Test/src>Finish
Right click defaultPackage>New File>HelloWorld.java
Enter code>Ctrls+s to save BAM, declared package does not match the expected package.
What Am I doing wrong that I am getting the error?
Thanks for your time
SOLVED: Instead of creating new package, I just clicked on SRC and created new file, naming it HelloWorld and it created the default package by itself.
Re: Problem with Eclipse - the declared package "" does not match the expected pack
You shouldn"t be creating a new file but a new class. If you tell the IDE you want a new class (HelloWorld in this case) it will create the correct souce file - HelloWorld.java - and put the correct package statement at the start.