• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New to java. Need help with errors.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From looking at just the error message, there seems to be a semicolon at an odd place...
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic