I have java 1.5 installed. If I attempt to run "java GameLauncher" using the GameLauncher.class as provided by the download, I get an exception stack "Exception in thread "main" java.lang.NoClassDefFoundError: GameLauncher (wrong name: chap2/GameLauncher).
If I erase all the *.class files and attempt to compile, javac Player.java gives me a "Player.class" file,
but then running "javac GuessGame.class" gets me a whole bunch of "Cannot find Symbol" errors class Player.
I haven't used those files recently, but if I remember correctly the downloaded files have package declarations in. So the files are not where you expect them to be.
When you create a file by hand and compile it, when beginning you tend to miss out the package declarations. So you get a MyClass.class file in your present directory, which you might execute with
If the files have a package declaration, then they should be in a folder with the same name as the package; some books use the chapter number as the package name. So your file ought to be in a folder called ch_02 or similar. Then you would have to execute it by writing
[Note the . not /, and you have to be in the parent directory where ch_02 is a sub-directory.]
Head First Java is designed to work with Java5.
If you try to compile GuessGame with package declaration, then the compiler will expect that all the other .class files are already there.
I can't remember whether GuessGame requires packages; I think it will work without package declarations. Try copying all the .java files into a guess directory, navigate to that directory and compile again. In this case "cannot find symbol" means there is a .class file missing. If all the .java files are in the same directory the compiler can probably create all the requisite .class files if you say
I hope that helps more than it confuses
Joined: Oct 13, 2005
And it's "javac GuessGame.java" not "javac GuessGame.class".
Joined: Feb 23, 2009
Thank you. Commenting out the package statements got me going. I'll have to check the documentation on how to use them later.
Apologies for the mis-typing of "GuessGame.class". Came at the end of a very long day.
Joined: Oct 13, 2005
And we do notice mispellings. For anything of any length use ctrl-c ctrl-v; as you will see here, we may believe people's posted code and assume the spelllling errors are the cause of the problem.