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: 8997
posted
0
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
posted
0
Ok...here is the code:
[ January 06, 2006: Message edited by: thejaswini ramesh ]
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
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
posted
0
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.
Stuart Ash
Ranch Hand
Joined: Oct 07, 2005
Posts: 637
posted
0
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
posted
0
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
posted
0
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
posted
0
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.
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.