wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Head First Java Ready-Bake Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java Ready-Bake Code" Watch "Head First Java Ready-Bake Code" New topic
Author

Head First Java Ready-Bake Code

Yannis Famelis
Greenhorn

Joined: Oct 06, 2010
Posts: 6
Good morning to all!

I'm a newcomer to this forum and what made me register is a problem I have with some ready code provided by Head First Java book so whoever has used this book or has an idea please help!
I have purchased the e-book and along with it there was a folder with all the examples and the code from the book. For whoever has gone through that, I'm in chapter 5 p.112. There, it says to copy a code and another two classes into the same directory. I have done that and classes GameHelper and SimpleDotCom compile but class Game (which in the certain part of the book is referred as SimpleDotComGame but in the examples folder is named just Game) does not and throws the errors shown in the attachment I have included. Unfortunately, the book does not say anything about that. Whoever has this book or not but can help please give me some solutions because I need to procced. Thanks!





Yannis Famelis
Greenhorn

Joined: Oct 06, 2010
Posts: 6
Sorry, I have included an attachment but I don't see it. How can I post a screenshot?
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
If they are just compiler errors, go ahead and just copy/paste them.


Everyday in every way, we get a little better.
jarco voorhees
Greenhorn

Joined: Sep 09, 2010
Posts: 17
By coincidence I am doing the same chapter.
I also have an error



error:


Clearly this is because of the fact that prompt is not declared anywhere.
Why the writers do not have this error is what my question is.

My Blog (Dutch) http://jarco.be -
"Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel."
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
If you are getting an "unresolved compilation problem", that is because you are using Eclipse (beginners are probably better off without an IDE), and there is something you missed earlier. There should be a red mark against a line in your code: put your mouse in the red mark and see the message which appears.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
jarco voorhees and Yannis Famelis, welcome to JavaRanch, both of you
jarco voorhees
Greenhorn

Joined: Sep 09, 2010
Posts: 17
Campbell Ritchie wrote:If you are getting an "unresolved compilation problem", that is because you are using Eclipse (beginners are probably better off without an IDE), and there is something you missed earlier. There should be a red mark against a line in your code: put your mouse in the red mark and see the message which appears.


I see the problem.
prompt cannot be resolved to a variable.
I only wander how the writers have done this exercise so i can continue the chapter
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

There is probably a typo in the book; the parameter is named pormpt where it should be prompt. Check if there is an errata list available.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jarco voorhees
Greenhorn

Joined: Sep 09, 2010
Posts: 17
Rob Prime wrote:There is probably a typo in the book; the parameter is named pormpt where it should be prompt. Check if there is an errata list available.


In my book it is written correctly and i made the code exactly the same. Still will not compile
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

jarco voorhees wrote:

These two spellings are different. Either you mistyped it, or the book has it wrong. "prompt cannot be resolved to a variable" is not a compiler error you will see if prompt is spelled correctly.
Yannis Famelis
Greenhorn

Joined: Oct 06, 2010
Posts: 6
First of all thank you all for your answers and Campbell Ritchie for your welcome. Jarco, glad you're in the same chapter. Maybe we can help each other but in the certain case you're getting a different error from me. The thing is that I copied and pasted the code from the book's examples folder and is giving me again these errors. Could you tell me how can I add a screenshot in my post to show you what I mean? I have paste the code in Notepad and compiled from the command prompt as the book suggests. Normally, I use NetBeans.
jarco voorhees
Greenhorn

Joined: Sep 09, 2010
Posts: 17
Yannis Famelis wrote:First of all thank you all for your answers and Campbell Ritchie for your welcome. Jarco, glad you're in the same chapter. Maybe we can help each other but in the certain case you're getting a different error from me. The thing is that I copied and pasted the code from the book's examples folder and is giving me again these errors. Could you tell me how can I add a screenshot in my post to show you what I mean? I have paste the code in Notepad and compiled from the command prompt as the book suggests. Normally, I use NetBeans.


copy the code from notepad. Then paste it in a new reply field on this forum. Select all the text and then press the code button above. Then it will go in a nice code window when you submit your comment .
jarco voorhees
Greenhorn

Joined: Sep 09, 2010
Posts: 17
Rob Prime wrote:
jarco voorhees wrote:

These two spellings are different. Either you mistyped it, or the book has it wrong. "prompt cannot be resolved to a variable" is not a compiler error you will see if prompt is spelled correctly.


oops. That is indeed my mistake. Thanks for the swift help.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

jarco voorhees wrote:
Rob Prime wrote:
jarco voorhees wrote:

These two spellings are different. Either you mistyped it, or the book has it wrong. "prompt cannot be resolved to a variable" is not a compiler error you will see if prompt is spelled correctly.


oops. That is indeed my mistake. Thanks for the swift help.

You're welcome

Yannis, please don't post screen shots with either code or error messages. If you are compiling from the command line, copy the code from the terminal window and paste it here:
- right click the window title bar
- select Edit, then Mark
- drag around the text you want top copy
- press Enter
- paste here

If you're using an IDE I believe you can copy the error messages directly.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Those instructions apply to Windows®; on *nix you simply need to highlight the code and edit-copy (or ctrl-shift-C).
Yannis Famelis
Greenhorn

Joined: Oct 06, 2010
Posts: 6
Ok, here are the errors. I don't know if you can figure out what's wrong but if it is necessary tell me how to attach the code. As I said in my first post, SimpleDotCom and GameHelper classes compiled. The problem is only with the Game class. Thank you!

C:\Users\Yannis\Documents\Head First Java>javac Game.java
Game.java:2: package helpers does not exist
import helpers.GameHelper;
^
Game.java:12: cannot access SimpleDotCom
bad class file: .\SimpleDotCom.class
class file contains wrong class: chap05.SimpleDotCom
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
SimpleDotCom theDotCom = new SimpleDotCom();
^
2 errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

You'll need to check out how packages work. Check out http://download.oracle.com/javase/tutorial/java/package/index.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
If you are still at the SimpleDotcom stage, it is probably better to delete the package statement from every class, and use the "unnamed package".
Yannis Famelis
Greenhorn

Joined: Oct 06, 2010
Posts: 6
I have already deleted every package statement but I get these errors again. Maybe if I sent you the files somehow to compile them would be more helpful?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
In that case delete the import statements too.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Except those that start with java. or javax.
Yannis Famelis
Greenhorn

Joined: Oct 06, 2010
Posts: 6
I've already done all of these but nothing! It is getting very frustrating and I prefer to quit than having my nerves broken. Later in the book, it has a new version of the game and instead of copying it I'll type it myself. I'll be back when I have more news, either good or bad. Thank you very much, all of you for your help and suggestions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java Ready-Bake Code