プログラム上でランダムなjava.lang.IndexOutOfBoundsExceptionエラーが発生し続けます。 何が間違っていますか? プログラムは正常に実行されますが、実際には長いforループですが、いくつかの要素については、そのエラーが発生しているように見えて、次の要素に進み、正常に動作します。IndexOutOfBoundsException - 時々のみ?
for (int i = 0; i < response.getSegments().getSegmentInfo().size()-1; i++) {
reservedSeats = response.getSegments().getSegmentInfo().get(i).getCabinSummary().getCabinClass().get(i).getAmountOfResSeat();
usedSeats = response.getSegments().getSegmentInfo().get(i).getCabinSummary().getCabinClass().get(i).getAmountOfUsedSeat();
System.out.println("Reserved Seats: " + reservedSeats);
System.out.println("Used Seats : " + usedSeats);
}
このエラーを防ぐにはどうすればよいですか?
にアクセスしたいです配列のルックアップ(実際にはループ本体)を実際に実行するコードを表示します。 –
@Aasmund:コードを追加 – jcotal
IOOB Exceptionはおそらく '.... getCabinClass()。get(i)'の部分で起こっていますか? getSegmentInfo()のサイズを使用できることは何ですか? – Jacob