Hi I'm new here. I do have some basic Java background but very minimal. I first learned it from school like a year ago.
I just started reading Head First Java 2nd Edition and I already have problems with the first two chapters.
First was the PhraseOMatic from chapter 1. I followed the directions at the side and typed the source code word by word. Now the problem was when I compile it. It displays "package System does not exist" when compiled in JCreator. It's the same in MSDOS also. I left it for a while to test it in school when i'll go there to check if they have the same result. I moved to chapter 2.
I also typed the code as it was written like this:
When I compiled it, it displays this: class GuessGame is public, should be declared in a file named GuessGame.java class Player is public, should be declared in a file named Player.java cannot find symbol class Guessgame
I'm 99% sure I don't have any typos ther.
BTW, I'm using the latest version Java SE. Thanks for your solutions in advance.
I haven't read HF java recently. But I guess they must have mentioned that all these classes need to be in different files. Either make all the classes expect the class with main method package private (remove the public from public class) or declare them in different files in the same directory.
till what extent i know we can have only 1 public class in 1 file. in the code you mentioned you have declared more than 1 " public " classes in 1 file try declaring all the classes in different files it might work out for you!
class GuessGame is public, should be declared in a file named GuessGame.java
is an error message with which I am all too familiar. What file name did you save your code under? It should have been saved as GuessGame.java. (Not, for example, as something like Chap2Game.java - which is what I tend to do ...)
Also, the advice about putting each public class in a file with exactly the same name as the class is exactly correct.
I am completely new to Java and am working my way through the same book. So far, pretty much all of the example code has worked for me.