I've gotten headaches from this too.  Usually a double loop works fine for
me:

Myclass test[][] = new Myclass[300][25];

Then in the constructor:
For (int x = 0; x < 300; x++)
{
    For (int y = 0; y < 25; y++)
   {
        test[x][y] = new Myclass();
    }
}

Works for me

On Feb 17, 2010 5:34 PM, "Jeffrey" <[email protected]> wrote:

I have a 2D array that I need to initialize. I have a class that holds
all my variables name "V", so in that class I have this:

static String[][] ModelInfo = new String[300][25];

That should make 300 array variables with 25 points in it, but it
doesn't as any time I try to reference anything other than
V.ModelInfo[0][0] I get arrayindexoutofboundsexception.

I have tried initializing this in a for loop, but even that won't
work. I've tried this:

V.ModelInfo = new String[300][];
                       for(int ForNum = 0; ForNum < 300; ForNum++){
                               V.ModelInfo[ForNum] = new String[25];
                       }
What the hell am I doing wrong? I found a work around at the moment
that does this:
                       for(int ForNum = 0; ForNum < 300; ForNum++){
                               V.ModelInfo[ForNum] = new StoredArray;
//StoredArray is
initialized as String[25].
                       }


Is there some trick to getting 2D arrays to actually work like they
are supposed to?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]<android-developers%[email protected]>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to