• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal start of type error

 
Alex Garci
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't name your variable final because that's a reserved word.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic