• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to java. Need help with errors.

 
John Alderdice
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have to do this assignment and I'm pretty much done except I have a few errors that I can't solve.


Error says
FishShopApp1.java:193: illegal start of expression
public static void displayMenu(); {
^
FishShopApp1.java:202: while expected
}


I'm using jGrasp is that helps. I'm seriously stumped at this.

Thanks for any help
[ August 13, 2006: Message edited by: fred rosenberger ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

There is a list of compiler error messages here, but in my experience "illegal start of expression" has to do with pairing off {}. It usually means you have one more { than you think, or one } fewer; the compiler thinks you are still inside a method. Unfortunately, unlike some IDEs, JGrasp doesn't automatically pair off () [] and {}.
Go back and count all your { and } and I think that will sort out your problem.

If you get the error with {} the other way round, it tens to say something like "class or interface expected."

CR
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From looking at just the error message, there seems to be a semicolon at an odd place...
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it may just be the way the forum is displaying your code, but it's good programming practice to indent your code properly
it's easier to read and helps a lot keeping the curly braces paired up correctly

Dave
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by David Robbins
indent your code properly
The way to keep indentation on the forum is to use "code" tags, from the "code" button below the "message" box.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i edited your original post to take out the 'quote' tags, and put in 'code' tags. this restored the formatting/indentation.

I haven't spent much time looking at this, but i'm pretty sure you don't want this:

while (choice != 4);

it's either going to give you an infinite loop, or do nothing.

the error message is most likely because your braces are off. the second-to-last brace actually is closing your switch statement (which i'm pretty sure is long after you mean to close it), and the last brace currently closes your do-loop. make sure you have all the braces you need...
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the (while choice != 4); bit is supposed to be the end of the "do-while" loop.
I am still not sure the thing will work even when the braces are sorted out. I can't understand how the pourTo() method in the FishTank class works, though I can guess the addIn() method.
There is also the risk of adding more water in the constructor than the tank will actually hold.
There is more in the assignment which I think will lose marks.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the (while choice != 4); bit is supposed to be the end of the "do-while" loop.

ahh... that makes sense. i always miss that when the formatting isn't right (and sometimes when it is.

but i'm still pretty sure there are missing braces.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic