This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

dumb array definition error, help!!!  RSS feed

 
Ranch Hand
Posts: 33
  • 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??
 
Sheriff
Posts: 9087
12
  • 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
  • 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).]
 
Ranch Hand
Posts: 88
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!