*
The moose likes Beginning Java and the fly likes dumb array definition error, help!!! 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 "dumb array definition error, help!!!" Watch "dumb array definition error, help!!!" New topic
Author

dumb array definition error, help!!!

capp luckett
Ranch Hand

Joined: Dec 07, 2000
Posts: 33
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??

flodin
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Looks like you're missing a square bracket somewhere prior to what you're showing us.

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

Joined: Dec 07, 2000
Posts: 33
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

Joined: Aug 06, 2001
Posts: 88
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

Joined: Dec 07, 2000
Posts: 33
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
 
subject: dumb array definition error, help!!!
 
Similar Threads
Need help on two compile errors
java abstract class
Null Pointer Exception Error - .contains(p)
Method call from mouseClicked
java abstract class