我知道这个问题已经被问了一百万次。而且我觉得这个解决方案对于几个小时没有注视过它的人来说是相当明显的。但是,我无法让自己超越界限的例外。以下是错误:Java数组列表outofbounds
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
我想也许这可能是由于到ArrayList的大小来发生的事情,但如果是这样的话我本来期望的误差加法的时候,而不是越来越成。这里是它垂死代码:
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
但它也死了,就弄,在追加。我错过了什么?
'System.out.println'列表中,你会看到你有更少的元素比你想象的 – slezica 2013-04-05 03:48:34
的问题是,你混淆了基于1的索引基于0的索引。如果你的列表有10个元素,元素存在的索引是'0-9'(当你使用'ArrayList.add(Object)'时,你的检查确保'ArrayList'中的索引存在'如果(CNT
nickb
2013-04-05 03:50:57