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 array prob for a new comer... 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 "array prob for a new comer..." Watch "array prob for a new comer..." New topic
Author

array prob for a new comer...

Stratos Geroulis
Greenhorn

Joined: Mar 14, 2004
Posts: 6
well hello all and thanks for taking me in. i have a litlle stupid array prob. i have a class called ArrayReverse with an array like "char charArray[]" and an instance of it called ArrRev. i am trying to do this: "ArrRev.charArray[2]={a,b};" and i keep gettin the message "illegal start of expression" pointing at the "{". what is that? can anyone help? thanks in advance.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Welcome to JavaRanch, Stratos Geroulis.

I think a little bit of code might be useful. I suspect that you are declaring and/or initializing your array incorrectly.
[ March 14, 2004: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Well Stratos, why don't you post your code and let us take a look at it. Be sure to use the code tags by pressing the CODE button below to make it easier to read. The syntax you show only applies to arrays so when you write a statement like ArrRev.charArray[2], unless charArray is a multi-dimensional array then the compiler will complain as you have indicated.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Tod Checker
Greenhorn

Joined: Feb 19, 2004
Posts: 27
ArrRev.charArray[2]={a,b}; This is an illegal declaration.
Try ArrRev.charArray[] = {a,b};
And if charArray is an attribute of ArrRev try using a setter instead of making it public like that.
Stratos Geroulis
Greenhorn

Joined: Mar 14, 2004
Posts: 6

this is something like i told you about yesterday.
i keep gettin the same compilation error "illegal start of expression" pointing at the "{".
please give me an answer anybody
thanks in advance....
[ March 15, 2004: Message edited by: Stratos Geroulis ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

You can only use the "shortcut" when you first declare the array. Also, you would need to enclose each of these elements in single quotes, or the compiler will think they are undeclared variables. so, something like

should work.


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

Joined: Mar 14, 2004
Posts: 6
thanks it works just fine.
 
Don't get me started about those stupid light bulbs.
 
subject: array prob for a new comer...
 
Similar Threads
Create Object in DoWhile Send to Arraylist
How to create a new .txt file from JSP ?
Problem in using javascript in spring web mvc system:
Files & file systems
Array problem.