• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

<identifier> expected  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I just recently started studying Java on my own using the book Head First Java and everything was going rather smoothly until the sixth chapter with the battleship-ish game, where I'm getting an error I have no idea how to fix since from what I know so far, the code's supposed to work.

I did check the web for the error and found some answers, however, most of them did not apply here (at least I don't think they do) since I'm declaring a method and the ones that were somewhat similar didn't work at all (for example, there was one that mentioned that the code given in the HFJ website worked once a line was fixed, but here it didn't work either.

For those familiar with the book, both the DotCom and GameHelper classes are on the same folder as the DotComBust and I typed them myself (they both compiled just fine).

And not sure if it makes any difference (shouldn't), but I'm doing all this on a mac, using the text edit to type all the code (but I have converted it to plain text instead of the default rich text).

Well, without further ado, here's the code:


And here's the error list:


The setName method refers to the DotCom class that is in another file at the same folder and is coded to take an n String.
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The lines flagged as errors are flagged because they are not declarations and they are not in a method (or constructor, etc).

You probably think they are in the checkUserGuess() method, but they aren't because you didn't quite write it correctly.

Look at line 36, which is the first line of the checkUserGuess() method. Now look at line 8, which is supposed to be the first line of the checkUserGuess() method. Notice any difference?
 
Greenhorn
Posts: 14
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
try to use some IDE. It will be very helpful for beginner.

the problem is in your methods :


i'm sure that was just a typo. Use '{' instead of ';' next to methods names.

Regards
 
Pedro Fonseca
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ow, duh!

I feel incredibly stupid to let such a simple mistake slip by, but thanks for the help it works like a clockwork now!

And thanks for the tip, it looks like it's indeed time to get an IDE.
 
lowercase baba
Bartender
Posts: 12628
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pedro Fonseca wrote:And thanks for the tip, it looks like it's indeed time to get an IDE.


Most of the old timers here would strongly recommend you NOT use an IDE. at least, not yet. If you are just learning java, you need to learn it. Using an IDE causes you to learn the IDE, and you miss some of the fundamentals.

I would also say you should NEVER have gotten this far on this code. NEVER NEVER NEVER write more than 2-3 lines before you compile. If the first time you attempt to compile you have 70 lines of code, you are in for a world of hurt.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!