• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

<identifier> expected

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic