希望有人可以幫助我,我要展示我的最後5個對象在我的ArrayList但顯示ArrayList中,有在我的代碼:(有些不對勁,需要幫助,請逆
for(int i=savedPreventivemachineList.size()-1 ; i < 5 ; i--)
{
Listresult.add(savedPreventivemachineList.indexOf(i), interventionmachine);
}
savedPreventivemachineTopList=Listresult;
當我執行它表明我這個錯誤:
java.lang.IndexOutOfBoundsException: Index: -1, Size: 0
java.util.ArrayList.rangeCheckForAdd(Unknown Source)
java.util.ArrayList.add(Unknown Source)
for(int i = savedPreventivemachineList.size() - 1; i> -1; i--)也許?你會下降,而不是上升,所以你需要比較,直到它獲得0的位置。你的循環將會是無止境的(不是真的,直到outOfBoundsException) – lummycoder