This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes game compile problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "game compile problems" Watch "game compile problems" New topic
Author

game compile problems

Brad Cantrell
Greenhorn

Joined: Aug 27, 2005
Posts: 22
Im getting a bunch of errors trying to compile the DotCom game (deluxe version) in Head First Java. If you can help me with this, I wont be bothering this forum with hardly any more compile problems because the book doesnt have any more programs for the next 300 pages or so. The program is made up of 3 files: GameHelper.java, DotCom.java, and the third the book is not clear what the name is, I think its DotComBust.java. So far the only file that compiles without errors is DotCom.java. The errors that come up with GameHelper.java are "cannot find symbol" errors and DotComBust gets "class or interface expected" errors. Heres the code:

GameHelper.java


DotComBust.java


DotCom.java
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3415
    
  12
Post the exact errors so that we can see what symbols it can't find and what lines the errors are on.


Joanne
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3415
    
  12
In DotComBust.java you have the line
} // close for loop

What for loop ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The first error message for DotComBust is going to complain about the startPlaying() method, expecting a class or interface. "Expected class or interface" always means that the compiler found something outside of any class that doesn't look like a class, which almost always means that you've got an extra close brace in there, which terminates the class early, which makes the later parts of the class look like "extra". And indeed, if you look at the setUpGame() method, we see



That line that says "close for loop" looks suspicious, as there is no for loop in that routine!

The indentation seems to suggest that your editor understood this problem, which is a good thing. Listen to the editor -- if the automatic formatting doesn't look properly nested, it generally means you've got an extra or missing brace or parenthesis, or a missing double-quote.

In GameHelper, some of the messages we be about not finding "gridLength". Look at the declaration of gridLength, remember that Java is case sensitive...


[Jess in Action][AskingGoodQuestions]
Brad Cantrell
Greenhorn

Joined: Aug 27, 2005
Posts: 22
Originally posted by Joanne Neal:
In DotComBust.java you have the line
} // close for loop

What for loop ?

Arrrgghh!!! I did it again, I forgot an entire for loop


Heres my error message after I corrected the GameHelper file:


And here is the modified GameHelper code:

[ August 31, 2005: Message edited by: Brad Cantrell ]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3415
    
  12
Reading Ernest's post will get rid of four of those errors (the getLength ones).

As for the second error. Did you really copy that line from a book ? If not, then think what you are actually trying to do. It will probably be better if you split it up into a couple of lines - the assignment and the test.
Brad Cantrell
Greenhorn

Joined: Aug 27, 2005
Posts: 22
Thank you everyone, I got it to compile. Sorry for rushing out a response without carefully reading all the posts but I had to rush to class. Not being able to get programs to compile has been a major block in teaching myself to program, Im very appreciate of your help. I hope I will be able to catch all this stuff myself next time.

-Brad
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Brad Cantrell:
...Not being able to get programs to compile has been a major block in teaching myself to program...


Get used to it. Compiler errors are a fact of life, even for professional programmers. It is very annoying to spend half an hour trying to fix a compiler error to finally figure out that you just forgot a semi-colon somewhere.

Of course, I'm talking about compiling the code I wrote myself here. It's probably even more frustrating when code from a book won't compile. However, when this happens for me, my first assumption is that I typed it incorrectly. Of course, even then, it is difficult to find the error even when you are carefully comparing with the code listing from the book.

Anyways, I hope you are enjoying learning how to program in Java. Please feel free to ask questions here often. In particular, learning what the compiler errors mean is a great skill to develop.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
Brad Cantrell
Greenhorn

Joined: Aug 27, 2005
Posts: 22
Thanks for that comment Layne. Some people on this forum seem to have some kind of Jedi power for spotting bad code. With me not even being able to copy code out of a book I was starting to get discouraged as to my having ability to program.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Brad Cantrell:
Thanks for that comment Layne. Some people on this forum seem to have some kind of Jedi power for spotting bad code. With me not even being able to copy code out of a book I was starting to get discouraged as to my having ability to program.


For most of us, this mysterious Jedi power comes from years of experience and seeing the same compiler errors hundreds of times. Like I said, learning what a compiler error means, and even more importantly, the most likely causes, makes life a lot less difficult and frustrating.

Layne
Patrick van Zandbeek
Ranch Hand

Joined: Aug 17, 2005
Posts: 37
Originally posted by Brad Cantrell:
...Not being able to get programs to compile has been a major block in teaching myself to program...-Brad


I'm sorry to disagree. Not being able to get programs to compile is a very important phase in becoming a good programmer.

If you type over code from a book and it compiles and runs fine in one go, you will have learned a few things. If it doesn't compile however and you have to hunt for bugs and spend some, admittedly frustrating, time trying to get it to run and having to force yourself to really understand what is going on in the code and what all that compiler error gibberish means, then you will have learned a LOT.


u is a letter, not a word.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: game compile problems
 
Similar Threads
Head First Java DotCom, DotComBust, GameHelper
DotComBustGame in HFJ -- not working; can't figure out what I've missed
Head First Java Programs
Head First Java P148 - DotComBust - compile errors
Head First Jave - Code Example - NullPointerException