나는 택시 물건을 잡을 arraylist를 만드는 프로그램을 가지고있다. 나는 메시지에서 얻은 것이 자바가 arraylist에 객체를 가지고 있다는 것을 인식하지 못한다는 오류를 계속 발생시킨다. 이것은 내가 얻고있는 오류입니다. 스레드에서Java에서 ArrayList의 요소를 인식하지 못합니까?
이예외 "주요"java.lang.IndexOutOfBoundsException : 인덱스 : 20, 크기 : java.util.ArrayList.rangeCheck 20
(알 수없는 소스) java.util.ArrayList.get에서
(이것은 내가 일을하려고 노력하고있는 코드가
알 수없는 소스) edu.Tridenttech.MartiC.app.CabOrginazer.main (CabOrginazer.java:48에서
)
public class CabOrginazer {
private static List<CabProperties> cabs = new ArrayList<CabProperties>();
private static int count = 0;
private static boolean found = false;
public void cabOrginazer()
{
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CabRecordReaper reaper = new CabRecordReaper("C:/CabRecords/September.txt");
CabProperties cabNum;
for(int i = 0; i < 20; i++)
{
cabNum = new CabProperties();
cabs.add(cabNum);
}
while(reaper.hasMoreRecords())
{
CabRecord file = reaper.getNextRecord();
for(int j = 0; j < cabs.size(); j++)
{
if(cabs.get(j).getCabID() == file.getCabId())
{
found = true;
cabs.get(j).setTypeAndValue(file.getType(), file.getValue(), file.getPerGallonCost());
cabs.get(j).setDate(file.getDateString());
break;
}
}
if(found == false)
{
cabs.get(count).setCabId(file.getCabId());
count++;
}
/*for(CabProperties taxi : cabs)
{
if(taxi.getCabID() == file.getCabId())
{
found = true;
taxi.setTypeAndValue(file.getType(), file.getValue(), file.getPerGallonCost());
taxi.setDate(file.getDateString());
break;
}
}*/
}
for(CabProperties taxi : cabs)
{
System.out.print("cab ID: " + taxi.getCabID());
System.out.print("\tGross earning: " + taxi.getGrossEarn());
System.out.print("\tTotal Gas Cost: " + taxi.getGasCost());
System.out.print("\tTotal Service Cost: " + taxi.getServiceCost());
System.out.println();
}
}
}
라인 48는 그 경우의 진술입니다. cabs.get(count).setCabId(file.getCabId());
나는 자바에 대해 조금 알고 있습니다. Java는 cabs
안에 요소가 있다는 것을 알아야하며 그 중 id
을 택할 수 있어야합니다. Java로 인해 arraylist가 채워지는 것을 인식하지 못하게 할 수 있습니까?