我工作的一個Android應用程序,並且從下面的代碼段得到一個奇怪的ArrayIndexOutOfBoundsException異常:需要調試怪異ArrayIndexOutOfBoundsException異常
String[] temp = q[i].answers;//retrieves a String array
String answers = "";
if (temp != null) {
if (temp.length > 0) {
for (int j = 0; j < temp.length; i++) {
if(temp[i]!=null) {
answers += temp[i];
if (i != temp.length - 1) {
answers += "|";
}
}
}
}
}
有人能幫助指出問題所在?我以爲我檢查了所有可能性。
哪一行是錯誤? –
@simplyianm它應該直截了當地通讀代碼,因爲我試圖檢查temp不是null,並且temp的大小大於0,錯誤在循環中,當我訪問temp [i ]。 – Phil