我知道这个问题已经被问了一百万次了。而且我觉得解决方案对于几个小时没有盯着它的人来说是相当明显的。但是我不能对我的越界异常做出正面或反面。这是错误:
exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 207493, Size: 207493
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at affysureselect.AffySureSelect.main(AffySureSelect.java:92)
Java Result: 1
我在想这可能是由于数组列表的大小而发生的,但如果是这种情况,我会预计错误是在添加时出现,而不是在获取时出现。这是它正在死亡的代码:
String chrompos;
ArrayList<String> chromnum = new ArrayList<String>();
while ((input2 = sbuff.readLine()) != null) {
prse = input2.split("\t");
chromnum.add(prse[0]);
...
chrompos = prse[7];
}
int cnt = 0;
int cnt2 = 0;
if (chromnum.get(cnt).equals(chrompos)) { // line causing my untimely death
end = Integer.parseInt(chromposend.get(cnt2));
start = Integer.parseInt(chromposstart.get(cnt2));
...
我什至尝试添加:
if (cnt <= chromnum.size()) { //this line
if (chromnum.get(cnt).equals(chrompos)) { /before the dying line
但它无论如何都会死,在获取时,而不是添加。我错过了什么?