所以错误信息是这样的:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at FcfsScheduler.sortArrival(FcfsScheduler.java:77)
at FcfsScheduler.computeSchedule(FcfsScheduler.java:30)
at ScheduleDisks.main(ScheduleDisks.java:33)
我的代码为
public void sortArrival(List<Request> r)
{
int pointer = 0;
int sProof = 0;
while(true)
{
if(r.get(pointer).getArrivalTime()<r.get(pointer+1).getArrivalTime())
{
Request r1 = r.get(pointer);
Request r2 = r.get(pointer+1);
r.set(pointer, r2);
r.set(pointer+1, r1);
}
else
{
sProof++;
}
++pointer;
if(pointer>r.size()-2)
{
pointer=0;
sProof=0;
}
if(sProof>=r.size()-2)
{
break;
}
}
}
错误在
if(r.get(pointer).getArrivalTime()<r.get(pointer+1).getArrivalTime())
但我认为在指针递增后用代码检查数组索引是否正常。它是数组越界异常还是其他?通常,错误是ArrayIndexOutOfBoundsException
当它是数组时。这里似乎有什么问题?