File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Syntax error on token "void", @ expected" Watch "Syntax error on token "void", @ expected" New topic
Author

Syntax error on token "void", @ expected

brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
In this program that i wrote that is part of a bigger program.. i got these errors on line 20 - Syntax error on token "void", @ expected - Syntax error on token(s), misplaced construct(s). tried searching the web but couldnt find anything.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You can't put a method inside another method.

Probably you didn't think you were trying to do that, but the inconsistent nesting of the braces in that code makes it hard to tell. If you're using an IDE, then ask it to reformat your code so the nesting makes sense.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Check your indentation, which is incorrect. You may have {} out of balance. Following an indentation convention can prevent all sorts of errors. Also you should write backwards, which can improve your indentation.
brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 34
thanks guys. that was it. writing backwards is key
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

yeah, good advice again Campbell. i made a habit of that a long time ago. it really helps.


SCJP
Visit my download page
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
You’re welcome

As Randall Twede has suggested, writing backwards is the result of experience, and this is the sort of place where you can share experience.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Syntax error on token "void", @ expected
 
Similar Threads
seemingly identical code producing 2 different outcomes.
Calling a variable form the main class
Need help
creating a list
Variables from another class won't assign to main class