0

下面的循环似乎停止了,然后重新启动。它不在另一个循环内。第一个 Log 调用打印 36,因此外部 for 循环应该运行 36 次。不过,循环内部的 Log 调用(用于打印循环运行的次数)会打印“0”到“4”,这意味着循环只运行了 5 次。这个过程是否有任何理由重新开始,以便第一次 Log 调用再次触发,并且循环再次运行仅 5 次?根据我的 Logcat 输出,这发生了两次。

ArrayList<RunData_L> rdUP = t.getMyPositiveRunData();
ArrayList<RunData_L> rdDOWN = t.getMyNegativeRunData();
Log.d("rdUP size", rdUP.get(0).getMyMeasurementData().size() + "");
for (int i = 0; i < rdUP.get(i).getMyMeasurementData().size(); i++) {
   Log.d("i", i + "");
   ArrayList<BigDecimal> tempUP = new ArrayList<BigDecimal>(), tempDOWN = new ArrayList<BigDecimal>();
   for(int j = 0; j < rdUP.size(); j++) {
      tempUP.add(rdUP.get(j).getMyMeasurementData().get(i));
      tempDOWN.add(rdDOWN.get(j).getMyMeasurementData().get(i));
   }
   pdUP.add(tempUP);
   pdDOWN.add(tempDOWN);
}
4

1 回答 1

0

I suspect as per my comment that the use of rdUP.get(j) in the inner loop is causing the problem.

You first test to see the size of rdUP.get(i).getMyMeasurementData() in the outer loop as your bounding condition for the loop and so i runs from 0 to the size of rdUP.get(i).getMyMeasurementData().

Your inner loop then says go through each element of rdUP and get the i th value from rdUP.get(j).getMyMeasurementData(). How do you know that the j th rdUP has enough elements to satisfy your get(i) ?

于 2012-07-26T18:57:44.713 回答