방금 java.lang.IndexOutOfBoundsException을 받았지만 발생 원인을 이해할 수 없습니다. 기본적으로, 나는 sqlite 테이블의 레코드를 listview에 통합하고있다. 다음은 테이블에서 레코드를 가져 오는 SQL 쿼리입니다.해결 방법 IndexOutOfBoundsException : 잘못된 인덱스 1, 크기가 1입니까?
public ArrayList<Integer> getRecordsCount(int no) {
ArrayList<Integer> count = new ArrayList<>();
Cursor c = database.rawQuery(
"select count(*) as TotalCount, tDate, " +
"strftime('%d', tDate) as DayPart, " +
"strftime('%m', tDate) as MonthPart, " +
"strftime('%Y', tDate) as YearPart " +
"from library " +
"where type = '" + no + "' " +
"group by MonthPart, YearPart", null);
while (c.moveToNext()) {
count.add(c.getInt(0));
}
return count;
}
이 내 방법은 데이터를 검색하는 것입니다 : -
public void setDataInList(int no) {
if (no == 0) {
ArrayList<Integer> count = helper.getRecordsCount(1);
mainGetLibraryModels.clear();
MainLibraryModelWS modelWS = helper.getAllRecordsMonthWise2(no);
for (int i = 0; i < modelWS.getRecords().size(); i++) {
WSLibraryModel model = new WSLibraryModel();
model.setAmount(modelWS.getRecords().get(i).getAmount());
model.setTotalCount("" + count.get(i));
model.setYearPart(modelWS.getRecords().get(i).getYearPart());
model.setMonthPart(modelWS.getRecords().get(i).getMonthPart());
mainGetLibraryModels.add(model);
}
adapter.notifyDataSetChanged();
} else if (no == 1) {
ArrayList<Integer> count = helper.getRecordsCount(2);
mainGetLibraryModels.clear();
MainLibraryModelWS modelWS = helper.getAllRecordsMonthWise2(no);
for (int i = 0; i < modelWS.getRecords().size(); i++) {
WSLibraryModel model = new WSLibraryModel();
model.setAmount(modelWS.getRecords().get(i).getAmount());
model.setTotalCount("" + count.get(i));
model.setYearPart(modelWS.getRecords().get(i).getYearPart());
model.setMonthPart(modelWS.getRecords().get(i).getMonthPart());
mainGetLibraryModels.add(model);
}
adapter.notifyDataSetChanged();
} else {
mainGetLibraryModels.clear();
MainLibraryModelWS modelWS = helper.getAllRecordsMonthWise2(no);
for (int i = 0; i < modelWS.getRecords().size(); i++) {
WSLibraryModel model = new WSLibraryModel();
model.setAmount(modelWS.getRecords().get(i).getAmount());
model.setTotalCount(" - ");
model.setYearPart(modelWS.getRecords().get(i).getYearPart());
model.setMonthPart(modelWS.getRecords().get(i).getMonthPart());
mainGetLibraryModels.add(model);
}
adapter.notifyDataSetChanged();
}
}
그러나, 나는이 코드를 실행하면, 그것은 내게 오류를 준다? 대신이의
FATAL EXCEPTION: main Process: com.teezom, PID: 14168
java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
때문에 – ThiepLV