• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

<identifier> expected error

 
Greenhorn
Posts: 3
Objective C Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Created a class Clock with displayTime(),displayMsg() methods to display time and required message.
I am getting 2 errors ,please help me find out my mistake.
they are-
<identifier>expected
and
';' expected

Please reply soon:rolleyes:



[Edit - added code tags - MB]
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lily. Welcome to the Ranch!

It's a lot more helpful if you tell us where the errors are occuring - the compiler will tell you which line it thinks is a problem, so it's useful to pass this on.

However, I can see a few problems. For example:

- You've got a static method (clock) referring to non-static variables (Hours, Minutes, Seconds). I suspect it's meant to be a constructor, but it isn't written as a constructor.

- You refer to AM and PM as if they are variables (e.g. line 53), but they aren't defined anywhere.
I suspect you're intending them to be Strings (they really ought to be enums, but maybe you haven't learned about them yet).

- On line 108, you've got missing brackets, and the capitalisation is wrong (Clock, not clock).

This isn't a complete list. You should really write just a bit of your class at a time, compiling regularly, rather than writing it all and then seeing what mistakes you've made. That way you've got a much better idea what's caused the problem.
 
lily jose
Greenhorn
Posts: 3
Objective C Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank ,
Now i have understood my mistake!
I am just a beginner in java, that's why i got my code messed up!
 
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
There's nothing wrong with making mistakes - in fact, it's one of the best ways to learn. and folks around here LOVE helping, but you have to help us help you. As Matthew pointed out, if you would post the exact and complete text of your errors, that makes it even easier to help you.

Let me also give you this piece of advice: Don't write 100+ lines of code before you compile. I personally NEVER write more than 2-3 before recompiling. That way, if there is a new syntax error, I know the exact 2-3 lines where the error must be.

After compiling, I test my new code - a LOT.

I write a LOT of throw-away code. I am a BIG proponent of putting in System.out.printin() statements all over the place that say things like "got to spot 1" or "in the outer for-loop" or "value of x is " + x.

I know it sounds silly and like a waste of time, but ultimately, especially when beginning, it really will SAVE you time.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic