2011-09-29 35 views
-2

我工作的一個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 += "|"; 
       } 
      } 
     } 
    } 
} 

有人能幫助指出問題所在?我以爲我檢查了所有可能性。

+0

哪一行是錯誤? –

+0

@simplyianm它應該直截了當地通讀代碼,因爲我試圖檢查temp不是null,並且temp的大小大於0,錯誤在循環中,當我訪問temp [i ]。 – Phil

回答

2

你增加我在for循環,而不是Ĵfor (int j = 0; j < temp.length; i++) ...第5行

+0

謝謝!我會在4分鐘內接受這個答案。 – Phil

1

在你的循環您測試變量「j」,但你遞增和索引與「我」。

編輯:Ninja'd

相關問題