日期:2014-05-20  浏览次数:20737 次

请问一下List的问题~~~~

public class GetData {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
List<List<Object>> temp1 = new ArrayList<List<Object>>();
        public List<List<Object>> getData(String s) throws ParseException,
IndexOutOfBoundsException {
try {
LoadCsv test = new LoadCsv(s);
List<List<String>> csvList = test.readCSVFile();

List<Object> temp2 = new ArrayList<Object>();
for (int i = 14; i < csvList.size(); i++) {
ArrayList temp = (ArrayList) csvList.get(i);
int j = 0;
// Object[] data1 = { 1, temp.get(2),
// sdf.parse((String) temp.get(1)), " ", temp.get(5),
// new Float(2), new Boolean(false), " ", "已付款", " " };
System.out.println(temp.get(2));
temp2.add(j++);
temp2.add(temp.get(2));
temp2.add(sdf.parse((String) temp.get(1)));
temp2.add(" ");
temp2.add(temp.get(5));
temp2.add(new Float(2));
temp2.add(new Boolean(false));
temp2.add(" ");
temp2.add("已付款");
temp2.add(" ");
temp1.add(temp2);
temp2.clear();
}
// Iterator it = list.iterator();
// while(it.hasNext()){
// Object s1 = it.next();
// System.out.print(s1);
// }

} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}

return temp1;
}


为什么会抛出java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source) 异常?
提示是temp2.add(temp.get(2));这里错了  纠结好久了 不知道怎么办~~~~~~~
该怎么处理啊?

------解决方案--------------------