This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cannot Figure Out This Syntax Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot Figure Out This Syntax Error" Watch "Cannot Figure Out This Syntax Error" New topic
Author

Cannot Figure Out This Syntax Error

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
I got syntax error on something very simple (please refer to the code below). It is very embarrassing! I do not understand the error messages:

1. syntax error on token(s), misplaced constructs; and
2. syntax error on token "path", VariableDeclaratorId Expected after this token


and
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
Why haven't you got that line inside a method?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That line isn't declaring a variable which isn't allowed on that location. You must place that statement in a method. The constructor for instance.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
I am in trouble.

In the ConsumerOrchestratorComponent class (where the syntax error happens), the tasks of that class are to

1. instantiate other components (lots of other components);
2. invoke methods on those instances. Other components have methods to carry out some work. The ConsumerOrchestratorComponent does not have method. Its work is to instantiate and invoke method on those instances.
3. Some methods in other components do not return anything.

Now, in the case that a method in another component does not return anything and the ConsumerOrchestratorComponent must instantiate that component and invoke the method on the instance, I have syntax error. What should I do?
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 561
Show us a code snippet and the exact error message you're getting.


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
In the ConsumerOrchestratorComponent class (where the syntax error happens), the tasks of that class are to

1. instantiate other components (lots of other components);
2. invoke methods on those instances. Other components have methods to carry out some work. The ConsumerOrchestratorComponent does not have method. Its work is to instantiate and invoke method on those instances.
3. Some methods in other components do not return anything.

Now, in the case that a method in another component does not return anything and the ConsumerOrchestratorComponent must instantiate that component and invoke the method on the instance, I have syntax error. What should I do?

code snippet:
Ted Smyth
Ranch Hand

Joined: May 28, 2008
Posts: 73
Natalie Kopple wrote:
code snippet:


That's not a valid class definition (you cannot place statements like "someObject.someMethod(params);" in a class body, they must be in a method or static initializer). This would be an example of a valid ConsumerOrchestratorComponent which does some "orchestration" via a static method:


You can then invoke it like this:
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
I have found out what to do. Thanks to all for your feedbacks. I appreciate them.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
You're welcome
 
GeeCON Prague 2014
 
subject: Cannot Figure Out This Syntax Error