aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 19541
    
  16

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
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: 10911
    
  12

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: 19541
    
  16

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: 13869
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Didn't even notice these.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: syntax error on token "else"
 
Similar Threads
i need help letting a user input anything all upercase, lowercase, or both.
Which is your favorite Star Wars Episode?
please help! simple java program of rock paper scissors
Refactoring Exercise
Rock Paper Scissors