Win a copy of Head First Go this week in the Go forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

what is "identifier expected" error?  RSS feed

 
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.
 
Sheriff
Posts: 9094
12
  • Likes 2
  • 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 ]
 
author
Posts: 14112
  • Likes 1
  • 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.
 
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.
 
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
  • Likes 1
  • 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
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...
 
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_
 
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.
 
Marshal
Posts: 63496
207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon Valdez,
Your post was moved to a new topic.
 
I want my playground back. Here, I'll give you this tiny ad for it:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!