aspose file tools*
The moose likes Beginning Java and the fly likes Head First Java pg. 37-38 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java pg. 37-38" Watch "Head First Java pg. 37-38" New topic
Author

Head First Java pg. 37-38

George Koenig
Greenhorn

Joined: Jul 26, 2003
Posts: 3
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.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
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
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
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
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Just remove the word 'public ' from the front of 'public class Player' and from 'public class GameLauncher' and it compiles/runs OK.
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
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.


doco
George Koenig
Greenhorn

Joined: Jul 26, 2003
Posts: 3
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
George Koenig
Greenhorn

Joined: Jul 26, 2003
Posts: 3
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java pg. 37-38