• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Head First Java Ready-Bake Code

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I have included an attachment but I don't see it. How can I post a screenshot?
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If they are just compiler errors, go ahead and just copy/paste them.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79667
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79667
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jarco voorhees and Yannis Famelis, welcome to JavaRanch, both of you
 
jarco voorhees
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jarco voorhees
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79667
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those instructions apply to Windows®; on *nix you simply need to highlight the code and edit-copy (or ctrl-shift-C).
 
Yannis Famelis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to check out how packages work. Check out http://download.oracle.com/javase/tutorial/java/package/index.html
 
Campbell Ritchie
Marshal
Posts: 79667
381
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79667
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case delete the import statements too.
 
Rob Spoor
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Except those that start with java. or javax.
 
Yannis Famelis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic