Reputation: 6648
How do I set up an 2d array (array of arrays in java)?
dmap = new sq[255][255];
for (int y = 0; y < 255; ++y)
for (int x = 0; x < 255; ++x)
dmap[x][y] = new sq();
where sq
is my other class doesn't work well- I get a long hang (2 mins) and no logging or printfs appear in Eclipse debug views (console + log).
Upvotes: 0
Views: 168
Reputation: 1474
At first You must initialize first dimension of array and then go to next, here is the right code:
sq dmap[][] = new sq[256][];
for (int x = 0; x < 255; ++x){
dmap[x] = new sq[256];
for(int y = 0 ; y < 255 ; ++y){
dmap[x][y] = new sq();
}
}
Upvotes: 1