*
The moose likes Beginning Java and the fly likes Illegal start of type; identifier expected problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Illegal start of type; identifier expected problem." Watch "Illegal start of type; identifier expected problem." New topic
Author

Illegal start of type; identifier expected problem.

Kathleen Tillman
Greenhorn

Joined: May 09, 2009
Posts: 12
Hi all,
I'm having a problem with my java program. I am trying to make a program where the user enters a product number and a quantity, then at the end of the program the total of the order pops up. I have gotten as far as the last statement on my code without compilation errors, but when I try to display the total it either won't show up (if I move it up a bracket) or I get a compilation error. Can someone possibly help me with this? Thanks!



The error I get is this:

----jGRASP exec: javac -g C:\jGRASP Projects\JavaLoopsandSwitchStatements.java

JavaLoopsandSwitchStatements.java:65: <identifier> expected
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: illegal start of type
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: illegal start of type
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: ')' expected
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: ';' expected
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: illegal start of type
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: <identifier> expected
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:65: ';' expected
JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);
^
JavaLoopsandSwitchStatements.java:66: reached end of file while parsing
}
(I apologize if I didn't format the errors correctly.)

Thanks, Kat
hemant Budhewar BamniBk
Ranch Hand

Joined: May 09, 2009
Posts: 33
Hi,


the error causing because the line
"JOptionPane.showMessageDialog(null, "The total is: " + orderAmount);"

is in Class not in method main.

Please enter this in main method,
this would solve your problem.
Kathleen Tillman
Greenhorn

Joined: May 09, 2009
Posts: 12
Thank you so much for your help. The last time I moved it up a line, I forgot to press "-1" to exit, so I thought it wasn't working.

Thanks!!
karthick Soundararaj
Greenhorn

Joined: Mar 09, 2009
Posts: 26
Kathleen Tillman wrote:I may sound like a dunce, but I'm not quite sure what you mean by "in class not in method main".
Does that mean I need to move it farther down or farther up? And wouldn't that screw up showing the total after the information has been entered? I'm really new to Java, so this may sound like a really dumb question, but I'm confused.
Thanks.


Last line of your code is out of the main method...


A java addict
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to JavaRanch

We have all had that sort of error ourselves. All lines of code have locations they can be put in, and (usually) places they can't. That line is a statement, so it has to be inside a method (or initialiser block, or constructor). In this case, it fits a method. You will also notice that you have got about 9 messages, all caused by the same error. You will get used to that soon enough.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal start of type; identifier expected problem.
 
Similar Threads
Beginner Java Question
sentinal controlled looop
Im screwed and floundering, HELP PLEASE!!!
'identifier' & 'illegal start of type' messages???
help with joption pane cancel button