• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal start of expression

 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The check boxes doesn't appear could you help me with it....

Thanks,
Radhika
 
Henry Wong
author
Marshal
Pie
Posts: 21005
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check boxes along with answers doesn't appear on the screen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic