• 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

Illegal start of type error

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't name your variable final because that's a reserved word.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic