我不知道为什么会生成 ArrayOutOfBoundsException!很可能我忽略了一些事情,因为我太累了,但如果有人能告诉我哪里出了问题,我将不胜感激。谢谢。
// 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; }
最佳答案
连同 Luther Blissett 的回答...
您是否在实例化数组和开始 for
循环之间修改 mIPAWidth
?我会将您的 for
条件更改为如下内容:
for(int px = 0; px < CircleLeft.length; px++)
这样您就知道px
的类型并且您知道您正在引用CircleLeft
数组的实际长度。它可能无法修复您的错误,但它仍然是一个好主意。
关于android - 我不知道为什么我会遇到越界异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3419348/