2011-09-29 75 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