This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Illegal Start of Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Illegal Start of Expression" Watch "Illegal Start of Expression" New topic
Author

Illegal Start of Expression

AnujS Sharma
Greenhorn

Joined: Jul 30, 2011
Posts: 15
Hi,

I am getting an error "Illegal Start of Expression" on the following code:



Here, NoOfJumps is a method defined in a class which does not have the main method. This method accepts 4 arguments namely

1)Integer
2)Integer
3)Integer
4)Integer Array


Can someone please explain why this error is coming up and what is the resolution for this?



Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

look at the previous line, and make sure it is ended correctly. Also, make sure your brackets are all correct. sometimes you are missing one, and the parser gets all confused.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
AnujS Sharma
Greenhorn

Joined: Jul 30, 2011
Posts: 15
I don't think so.

Here is the full code.


Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
According to me instead of this try this
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Rameshwar is right. You can use the short {} initialization only directly when declaring: You can't use it when calling a method, and not even when giving an existing array variable a new value.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
Using the ellipsis operator allows you to change the array parameter to varargs, then you can write 1, 2, 3 rather than {1, 2, 3}.
AnujS Sharma
Greenhorn

Joined: Jul 30, 2011
Posts: 15
Thanks for all the help. Learnt something today.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Illegal Start of Expression
 
Similar Threads
SCJP 1.5 - Procedure for registration.
Access modifiers within methods
why does java give an error in the comment?
array declaration and creation
Variable Declaration in Main Method