• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dumb array definition error, help!!!

 
capp luckett
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again. (I am running up against a deadline.)
I get an error in defining this array of rectangles.
The definition compiles but each cell of the array errors:
"']' expected rect [0] = new Rectangle (0, 0, 100, 100);"
The error looks like:

Rectangle [] rect = new Rectangle [9];
rect [0] = new Rectangle (0, 0, 100, 100); // a0
rect [1] = new Rectangle (100, 0, 100, 100); // a1
rect [2] = new Rectangle (200, 0, 100, 100); // a2
rect [3] = new Rectangle (0, 100, 100, 100); // b0
rect [4] = new Rectangle (100, 100, 100, 100); // b1
rect [5] = new Rectangle (200, 100, 100, 100); // b2
rect [6] = new Rectangle (0, 200, 100, 100); // c0
rect [7] = new Rectangle (100, 100, 100, 100); // c1
rect [8] = new Rectangle (200, 200, 100, 100); // c2
Where am I wrong??
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you're missing a square bracket somewhere prior to what you're showing us.
 
capp luckett
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did find that I had one to many "{" in the init; that was not the problem.I did not see it, so, here is the whole source, thanks:


[This message has been edited by Cindy Glass (edited October 09, 2001).]
 
Colin Kenworthy
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Capp,
You are simply using the wrong syntax. To define an array in the place you have chosen to (i.e. in some free floating initialisation at the top of the class definition) you must do it like this -
String [] strArr = {"this", "is", "four", "Strings"};
which creates an array of 4 String objects. So for your example you must use -

Alternatively you can code it the way you have chosen to but it should be within a method. The syntax you are using "rect[n] = new Rectangle(i,j,k,l);" will work within a method. Try moving it inside the init() method and see.

[This message has been edited by Cindy Glass (edited October 09, 2001).]
 
capp luckett
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I have a two more compile errors to get rid of.
Been up most of the night, so I will repost another question
about the other two errors.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic