This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

game compile problems

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the exact errors so that we can see what symbols it can't find and what lines the errors are on.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In DotComBust.java you have the line
} // close for loop

What for loop ?
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Brad Cantrell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

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

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

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.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic