开发者

I don't know why I'm getting an out of bounds exception?

I don't know why this is generating an ArrayOutOfBoundsException! It's likely I've overlooked something because I'm so tired but if someone could tell me what is wr开发者_开发百科ong I'd appreciate it. Thanks.

// array declaration
public int CircleLeft[] = new int[mIPAWidth];

// this is my loop that generates the error:
for(px = 0; px <= mIPAWidth - 1; px++){
py =(int) m.sqrt(r^2 - (px-mIPAWidthHalf)^2) + mIPAHeightHalf;
Log.w(getClass().getName(), "mIPAWidth = " + mIPAWidth + ", index is: " + px);
CircleLeft[px] = py; }


Along with Luther Blissett's answer...

Are you modifying mIPAWidth between when the array is instantiated and when you begin the for loop? I would change your for conditional to something like this:

for(int px = 0; px < CircleLeft.length; px++)

That way you know the type of px and you know you're referencing the actual length of the CircleLeft array. It may not fix your error, but it's still a good idea.


What is the type of px? If it's a double, then you could suffer from a mis-compare with the <=(comparing for equality with double is almost never correct). Try the canonical loop for(px = 0; px < mIPAWidth ; px++) instead or better yet, make the loop index an integer.

Also, what's the type of mIPAWidth (for the same reasons)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜