Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

syntax error on token "else"

 
Abel Gonza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't seem to figure out why this is happening. Any tips at all will be very appreciated.
syntax error on token "else", delete this token.



I'll post all the code if requested.




 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

After the word "else" there shouldn't be any guard anymore - just the { or statement. That statement can be another "if", which is what I think you want:
Also, are you aware of method equalsIgnoreCase? You can use that to shorten your code:
 
Abel Gonza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Welcome to the Ranch!

After the word "else" there shouldn't be any guard anymore - just the { or statement. That statement can be another "if", which is what I think you want:
Also, are you aware of method equalsIgnoreCase? You can use that to shorten your code:



What do you mean guard?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and else statement doesn't have a condition on it. The idea is that on the IF and IF-ELSE lines, you have handled most conditions. the ELSE is for everything that wasn't caught by the previous statements. the general flow should be:


 
Abel Gonza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abel Gonza wrote:What do you mean guard?

Sorry, that's the term I once learned for it. I guess in Java it's more often called the condition.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised nobody noticed this yet: you have a ; after your if-statements that should not be there.

This must be:

 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't even notice these.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic