• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dumb array definition error, help!!!

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic