Click to See Complete Forum and Search --> : imho strange error with arrays:


skippy
May 6th, 2000, 06:42 AM
Hi !
I have a canvas-derived class used in an applet.
I have declared a variable global to this class:

public
class LView1
extends Canvas
{
private int[][] laby = new int[75][75];
private int labSize;
private Image screenImageBuffer;
private Graphics screen;
private Image[] stoneImageBuffer = new Image[stoneCount];
....




In the constructor, I define this Array:

public
LView1()
{
super();
this.setSize(300,300);

for (int i=0;i<30;i++)
{
for (int j=0;j<30;j++)
{
laby[i][j] = 1;
}
}

this.repaint();
}




When I try to access any index of this Array, at this point everythings ok.
But later, in another procedure, I get an
ArrayIndexOutOfBoundsException,
as soon as i or j become larger than 29.

public
boolean updateView()
{
screenImageBuffer = createImage(300,300);
screen = screenImageBuffer.getGraphics();

for (int i=0;i<labSize;i++)
{
for (int j=0;j<labSize;j++)
{
drawSingleStone:{
for (int playerNr=0;playerNr<4;playerNr++)
{
if ((i == player[playerNr].x)&&(j == player[playerNr].y))
{
screen.drawImage(stoneImageBuffer[11+playerNr],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
break drawSingleStone;
}
}
screen.drawImage(stoneImageBuffer[laby[i][j]],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
}
}
}
this.repaint();
return true;
}
}




Any suggestions?

cu
Skippy

weaver
May 6th, 2000, 07:45 AM
I think the problem might be because you're not specifing both indexes of the array. Try using

laby[i][j] = 1; instead of laby[j] = 1;

-------------------------------------------
weaver
icq# 64665116
Please rate this post.
http://weaver.x7.htmlplanet.com

skippy
May 6th, 2000, 01:55 PM
Hi !
Yes absolutely good point. But there is a
thing to say : I do use laby<i>[j],
but if you write that here with both brackets like this ( [ ), the <i> is interpreted as
bold, I'm sorry, I thought between the
<javacode> tags I could write what I want.
I'm sorry for that.

cya
Skippy