aspose file tools
The moose likes Beginning Java and the fly likes [SOLVED] Syntax error on token Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "[SOLVED] Syntax error on token" Watch "[SOLVED] Syntax error on token" New topic
Author

[SOLVED] Syntax error on token

Rico Cordova
Greenhorn

Joined: Oct 05, 2011
Posts: 5

I'm getting an error in my code that I can't seem fix. Below is a simplified example of what the code looks like:



Where,



The exact error is:
Syntax error on token "foo", Identifier expected after this token

Which occurs on line 4 in the Main.

I've done some Google searches and most of the suggestions deal with double checking braces. I'm convinced the braces situation is fine and can't figure out what is going on.

I'm pretty new to Java still - but experience with C++ so OO concepts aren't new to me.

Any suggestions?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754



You is calling a method inside the class scope. You must have a method of your class to call another method. That is why the code bellow will work.



[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Rico Cordova
Greenhorn

Joined: Oct 05, 2011
Posts: 5

I think I understand what you are saying. So if I made the following change it should work?

Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Does this work?


If that works, you'll get to know why it works as you learn java
Nomaan Butt
Ranch Hand

Joined: Oct 19, 2011
Posts: 54
Hi Rico,


this code will not work, you need to create the object of Main class and call fooBar() then. This can be done in main() method of public class or from any other method.
Nomaan Butt
Ranch Hand

Joined: Oct 19, 2011
Posts: 54
like this,

Rico Cordova
Greenhorn

Joined: Oct 05, 2011
Posts: 5

I understand now. Thanks, guys. Java having everything as a class still throws me slightly on how to call methods and where to instantiate objects.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [SOLVED] Syntax error on token
 
Similar Threads
what will happen if we make a constructor private?
Error reading from input file?
Quick Coding Style Question
Arrays of Objects
ClassCastException going from interface to object