aspose file tools*
The moose likes Beginning Java and the fly likes what is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is "identifier expected" error?" Watch "what is "identifier expected" error?" New topic
Author

what is "identifier expected" error?

thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Ok...here is the code:

[ January 06, 2006: Message edited by: thejaswini ramesh ]
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
It's an import problem. Either you haven't imported these classes or the jar is not found. Please check this.


ASCII silly question, Get a silly ANSI.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
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

Joined: Oct 19, 2005
Posts: 74
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Dec 15, 2005
Posts: 108
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_


Mike Noel
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
Brandon Valdez,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is "identifier expected" error?
 
Similar Threads
imports
array.length
Cant seem to get this to run as an applet?
var-args doubt...
Autoboxing, checking is two objects refer to the same object