我现在很困惑.我有一个ArrayList,我添加一个元素到ArrayList.现在ii尝试list.get(0)并抛出IndexOutOfBounds.......它变得更加奇怪:简而言之它看起来像这样:
ArrayList<SomeCustomClass> list = new ArrayList<SomeCustomClass>();
list.add(new SomeCustomClass());
int index = 0;
for(index = 0;index < list.size();index++){
if(list.get(index).something < somethingOther){ //Throws no error
break;
}
}
SomeCustomClass blarg = list.get(index); //Throws IndexOutOfBounds
Run Code Online (Sandbox Code Playgroud)
...为了确保,我在控制台中测试索引的值,它们都为零,但第二个引发错误.
提前致谢
编辑:Sry.我在问题中犯了错误.现在问题应该是正确的.是的:我检查索引是否有时超过0(它不是),如果"if"为真(它是)
编辑:搞笑:我手动改变指数为0,它是sais:
线程"Thread-2"中的异常java.lang.IndexOutOfBoundsException:索引:0,大小:0
我将0更改为1并且:
线程"Thread-2"中的异常java.lang.IndexOutOfBoundsException:索引:1,大小:1
(我只更改了错误来自的行中的值)Java是否在拖我?>.<:P