Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array prob for a new comer...

 
Stratos Geroulis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tod Checker
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stratos Geroulis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks it works just fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic