my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array prob for a new comer..." Watch "array prob for a new comer..." New topic

array prob for a new comer...

Stratos Geroulis

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

Joined: Jul 22, 2000
Posts: 9044
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 ]

"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

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

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

Joined: Oct 02, 2003
Posts: 11169

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

Joined: Mar 14, 2004
Posts: 6
thanks it works just fine.
I agree. Here's the link:
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.