I'm using Head First Java as a learning tutorial and the example on pg. 37-38 does not compile. Returns a "class Player is public, should be declared in file named Player.java. Same for GameLauncher. I tired to compile them separatly but then I get other errors. The book's web site doesn't have a contact page so I'm trying here as some of the contributors also contribute to this site. My apologies if this posting is inappropriate as I realize it's meaningless without seeing the book.
Well.. most of us don't have that book (yet), so it'd be great if you explain more the context of the problem, and if you can add some code snippets we will all try to help you.
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
The very first thing is to make sure that the code for the Player class is in a file called Player.java. Case is important - only the "P" should be capitalized, the rest of the letters should be lower case. Joe
George; I typed in code word for word as it is in the book - everything compiles and works as advertised - as is. My guess is as Joe suggested: make sure the case of the file you saved is the same of the name of the class in your code.
I removed 'public' from the 3 classes and compiled using GameLauncher.java (I had been using GuessGame.java) and it worked. I'd like to ask doco if he typed all three classes into one file and saved it as GameLauncher.java as that's what I tried and still got the error - class public... needs own file when I tried to compile. Thanks to all who wrote to help, I'm sure I'll be back for more. -george
I finally got it to work as written. Each 'public' class is in it's own classname.java file and the classname.java file which contains 'main' is the only one you compile with javac the others automatically get compiled. Thanks again -george
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
a bit of art, as a gift, that will fit in a stocking