• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with brackets and switch statements.  RSS feed

 
Anthony Ford
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I've been working on a school project for the past couple weeks in an object oriented design class. I'm stumped on something that seems simple so I need some new eye. I've talked to a friend taking another java class (gui based), I've spent hours playing with brackets and break; lines. I think I'm just mentally exhausted so it was suggested I ask for some help.

I'm using Dr. Java. Went through and corrected all the dumb little errors I've made (mostly capitalization, misspellings, etc.) but the last two still remain. They seem so simple yet for the life of me I can't figure it out. It has to be something I'm completely not seeing, or I'm trying to code beyond my skill by using multiple switch statements to do submenus. Here are the errors:

2 errors found:
File: C:\..\StoreMain.java [line: 162]
Error: Syntax error on token "{", } expected after this token
File: C:\..\StoreMain.java [line: 196]
Error: Syntax error on token "{", } expected after this token

Here is the code, I'm only including everything in the main where errors occur. I've isolated the problem to here, everything else compiles fine when I comment out the bad code. Keep in mind this is nowhere near finished, I just wanted to get basic functionality up and running. I still need to add error checking and a lot of other housekeeping code, format things to make them look presentable, etc. We weren't provided any data to start with so I built it to accept new data/objects and was going to input some test data on my own to get started but I can't even get to that point.

Thanks in advance!

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A switch statement can contain case statements, but not other code. You need to move the while loops elsewhere.
 
Anthony Ford
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was quick, thanks a lot!
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will always find it hard to find compiler errors if you write that much code. Write no more than 10 lines, compile it, and look for the errors. It is much easier like that.

And welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!