This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Illegal start of type error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Illegal start of type error" Watch "Illegal start of type error" New topic
Author

Illegal start of type error

Alex Garci
Greenhorn

Joined: Feb 14, 2012
Posts: 15
Hi,

I'm trying to fix the Illegal start of type error but I can't do it. I have the following code but I don't know why I display it:



The error is displayed in those two methods of the code.
Why I display this error?

Thanks.

[Edit - reformatted and added code tags - see UseCodeTags for details]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

You can't name your variable final because that's a reserved word.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Alex, Welcome to Javaranch.
Please post a properly formatted code using CodeTags.

In the while loop (which you have highlighted in red) has a semicolon at the end which is not valid.
Also such errors are due to a syntactical mistake elsewhere, so you might want to carefully verify your code for such errors. A properly formatted code will help in tracking such issues with much ease.


Mohamed Sanaulla | My Blog
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Rob Spoor wrote:You can't name your variable final because that's a reserved word.

Oh yeah how did I miss that one. My bad.
Alex Garci
Greenhorn

Joined: Feb 14, 2012
Posts: 15
Hi,

I just fixed errors. The problem was in word final, that is a reserved word. But I declared this variable naming it fin, but I didn't realize. I checked brackets, semicolons but the error was not fixed. The problem was in the final word.

Thank you for answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Mohamed Sanaulla wrote:In the while loop (which you have highlighted in red) has a semicolon at the end which is not valid.

It's valid, but it means the loop body is empty. Unless the loop condition turns itself to false the loop will run forever. One example from C is a (unsafe) string copy:
Another (contrived) example with a for loop, to print all elements of a List:
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Rob Spoor wrote:
Mohamed Sanaulla wrote:In the while loop (which you have highlighted in red) has a semicolon at the end which is not valid.

It's valid, but it means the loop body is empty. Unless the loop condition turns itself to false the loop will run forever. One example from C is a (unsafe) string copy:

I thought it was only for for-loop. Thanks for correcting!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3506
    
  14
Rob Spoor wrote:
Mohamed Sanaulla wrote:In the while loop (which you have highlighted in red) has a semicolon at the end which is not valid.

It's valid, but it means the loop body is empty.

It's also valid when it's at the end of a do/while loop which is the case in the OP's code (assuming we are talking about line 52 - the red seems to have disappeared)


Joanne
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Mohamed Sanaulla wrote:
Rob Spoor wrote:
Mohamed Sanaulla wrote:In the while loop (which you have highlighted in red) has a semicolon at the end which is not valid.

It's valid, but it means the loop body is empty. Unless the loop condition turns itself to false the loop will run forever. One example from C is a (unsafe) string copy:

I thought it was only for for-loop. Thanks for correcting!

It's for most statements; for, while, if, else, etc. There's an exception for try/catch/finally though, because these really wouldn't make sense without bodies.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Joanne Neal wrote:
Rob Spoor wrote:
Mohamed Sanaulla wrote:In the while loop (which you have highlighted in red) has a semicolon at the end which is not valid.

It's valid, but it means the loop body is empty.

It's also valid when it's at the end of a do/while loop which is the case in the OP's code (assuming we are talking about line 52 - the red seems to have disappeared)


Oh I didnt see the do.. while there. I just thought it was only while loop. Now that the code has been formatted (thanks to Matthew, I tried but I failed), its more clear as to what is what.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4377
    
    8

Joanne Neal wrote: (assuming we are talking about line 52 - the red seems to have disappeared)

Yeah, the colour formatting doesn't work once you've added code tags.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3506
    
  14
Mohamed Sanaulla wrote:Oh I didnt see the do.. while there. I just thought it was only while loop.

Don't worry. It took me a couple of looks before I noticed it (and that was after the code had been formatted). Normally I'm fairly agnostic on where { and } are put (same line, new line, whatever) but in the case of a do/while I think it's very useful if the which goes on the same line as the }. Makes the code much clearer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal start of type error