• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is "identifier expected" error?

 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I've been working on java for around 2 months...I have a very basic doubt...when do you get the error <identifier> expected?
I've written a small application where input is accepted by a textfield and based on some condition a dialog should be displayed saying "invalid i/p".But am not able to correct ths particular error,so pls some one help me out here.
Thanks in advance.
Thejaswini.
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure all your semicolons are in place. Otherwise, I suggest that you post the lines of code around the line specified in the error message.
 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...here is the code:

[ January 06, 2006: Message edited by: thejaswini ramesh ]
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's an import problem. Either you haven't imported these classes or the jar is not found. Please check this.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot put code directly into the class body. Your method calls need to be inside a method, constructor or static/instance initializer.

Sounds like you most likely should make all the fields and the createAndShowGUI method non-static and put the initialization into a constructor.
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
You cannot put code directly into the class body. Your method calls need to be inside a method, constructor or static/instance initializer.

Sounds like you most likely should make all the fields and the createAndShowGUI method non-static and put the initialization into a constructor.


Oh yeah! That too..
 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ilja & Stuart

The problem was a combination of what both of you suggested.I had forgotten some of the imports plus the initialization was not in a constructor.Yup now i managed to correct these.
Thanks once again.
Thejaswini.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stuart Ash:

Oh yeah! That too..


I have to admit that I missed it on the first scan, too...
 
Mike Noel
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems to be a frequent problem (code outside a method) around here. I would have never thought to put code outside of a method so I almost always fail to notice that mistake in other code. Guess I should start noticing it.

_M_
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Noel:
This seems to be a frequent problem (code outside a method) around here. I would have never thought to put code outside of a method so I almost always fail to notice that mistake in other code. Guess I should start noticing it.

_M_


But you can have such code in static or instance initializer blocks remember.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon Valdez,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic