my dog learned polymorphism
The moose likes Beginning Java and the fly likes syntax error on token Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "syntax error on token "else"" Watch "syntax error on token "else"" New topic
Author

syntax error on token "else"

Abel Gonza
Greenhorn

Joined: Sep 05, 2011
Posts: 3
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

Joined: Oct 27, 2005
Posts: 20083
    
  30

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Abel Gonza
Greenhorn

Joined: Sep 05, 2011
Posts: 3
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

Joined: Oct 02, 2003
Posts: 11861
    
  18

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:



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Abel Gonza
Greenhorn

Joined: Sep 05, 2011
Posts: 3
got it thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20083
    
  30

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

Joined: Aug 16, 2005
Posts: 14961
    
  26

I'm surprised nobody noticed this yet: you have a ; after your if-statements that should not be there.

This must be:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20083
    
  30

Didn't even notice these.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: syntax error on token "else"
 
It's not a secret anymore!