• Post Reply Bookmark Topic Watch Topic
  • New Topic

[SOLVED] Syntax error on token  RSS feed

 
Rico Cordova
Greenhorn
Posts: 5
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.

 
Rico Cordova
Greenhorn
Posts: 5
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I understand what you are saying. So if I made the following change it should work?

 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this work?


If that works, you'll get to know why it works as you learn java
 
Nomaan Butt
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
like this,

 
Rico Cordova
Greenhorn
Posts: 5
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!