File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Illegal start of expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Illegal start of expression" Watch "Illegal start of expression" New topic
Author

Illegal start of expression

Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
This program is a mathematical quiz .........



I get the following error :

----jGRASP exec: javac -g C:\Java Working Directory\MathTest1.java

MathTest1.java:67: illegal start of expression
public void init()
^
MathTest1.java:67: illegal start of expression
public void init()
^
MathTest1.java:67: ';' expected
public void init()
^
MathTest1.java:115: illegal start of expression
public void paint(Graphics gr)
^
MathTest1.java:115: illegal start of expression
public void paint(Graphics gr)
^
MathTest1.java:115: ';' expected
public void paint(Graphics gr)
^
MathTest1.java:115: ';' expected
public void paint(Graphics gr)
^
MathTest1.java:157: illegal start of expression
public void itemStateChanged(ItemEvent e)
^
MathTest1.java:157: illegal start of expression
public void itemStateChanged(ItemEvent e)
^
MathTest1.java:157: ';' expected
public void itemStateChanged(ItemEvent e)
^
MathTest1.java:157: ';' expected
public void itemStateChanged(ItemEvent e)
^
11 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Thanks,
Radhika
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Check your indentation.
You have put all your methods inside main.

If you are using a simple editor which does not handle indentation for you, it is always a good idea to declare the methods first, curly braces and all, and then write the actual implementation.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

MathTest1.java:67: illegal start of expression
public void init()


Check just before this line.

Also I agree with what Maneesh says, indentation makes the code more easily readable and helps you spot errors.

Sean


I love this place!
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
Let me see if I'm right I've removed the main method... I was missing this
import java.awt.event.*;
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
The check boxes doesn't appear could you help me with it....

Thanks,
Radhika
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

Radhika Srinivasan wrote:The check boxes doesn't appear could you help me with it....

Thanks,
Radhika


Help with what? You tried to declare a method inside another method. Don't do that.

And what is this "check boxes" fix you are attempting?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Did you read what Maneesh wrote?

You cannot declare methods inside methods. What you did, is put the init() method inside the main() method. That doesn't work. Did you forget a } at the end of the main() method, just before the init() method?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
I tried "}" before init() it doesn't work since I have declared. So I've removed the main method. But the checkboxes which includes answer doesn't appear in the applet.

I'm totally confused.., Please help me getting it right........

Thanks,
Radhika
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
This is my 1st project when I execute it works this way in commad prompt mode, in the present project I've modified it to work in applet.
----jGRASP exec: java MathTest

1. 7+2 = ? a.6 b.8 c.9 d.10
Enter Your Answer:
c
Correct
2. 9-5 = ? a.2 b.4 c.6 d.8
Enter Your Answer:
b
Correct
3. 144/12 = ? a.10 b.12 c.14 d.16
Enter Your Answer:
b
Correct
4. 5*5 = ? a.10 b.20 c.25 d.125
Enter Your Answer:
c
Correct
5. 2+3+5 = ? a.7 b.8 c.9 d.10
Enter Your Answer:
d
Correct

You had 5 question correct.

Congratulations,you passed with a score of 100%


----jGRASP: operation complete.
I have included my 1st project :
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

I don't understand. Does it work or not? do you have a problem or don't you?

I'm not trying to be rude... I just can't figure out what help (if any) you need. Your original post said "I'm getting this error". Several people told you what was wrong, but it doesn't look like you took their advice or clarified what the issue was.

My suggestion would be this:

State VERY CLEARLY what the exact problem is. Don't post 200 lines of code and say "There is a problem here somewhere", but only the relevant portion of the code DIRECTLY related to your problem.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
I got rid of the problem "Illegal start of expression" by including
import java.awt.event.*;
as well I removed the methods which were inside the main method.

Presently I'm having problem with "the checkboxes along with the answers" appearing on the screen to select the choices of answers from the quiz question.

Thanks,
Radhika
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
Check boxes along with answers doesn't appear on the screen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal start of expression
 
Similar Threads
How to display the output using Labels??
Some of you are experts this could be your next problem!
I would like to know the format to display the output at a particular location
Need ur suggestion... Urgent!
why do the two errors come out?