my dog learned polymorphism*
The moose likes Beginning Java and the fly likes New to java. Need help with errors. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New to java. Need help with errors." Watch "New to java. Need help with errors." New topic
Author

New to java. Need help with errors.

John Alderdice
Greenhorn

Joined: Aug 13, 2006
Posts: 1
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

Joined: Oct 13, 2005
Posts: 38481
    
  23
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

Joined: Jul 11, 2001
Posts: 14112
From looking at just the error message, there seems to be a semicolon at an odd place...


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
Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
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

Joined: Oct 13, 2005
Posts: 38481
    
  23
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

Joined: Oct 02, 2003
Posts: 11256
    
  16

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...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
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

Joined: Oct 02, 2003
Posts: 11256
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to java. Need help with errors.