下面是一些通过ArrayList
循环并对内容进行计算的代码:
for(int i = 0; i < triangularContent.size(); i ++) {
Triangle3D tri = triangularContent.get(i);
...
此代码应该可以正常工作,但是会抛出IndexOutOfBoundsException
:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 8, Size: 12
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at com.happyryan2.raycaster.raycaster.RayCaster.raycast(RayCaster.java:114)
at com.happyryan2.raycaster.raycaster.RayCaster.rotatePosToPlayerView(RayCaster.java:73)
at com.happyryan2.raycaster.raycaster.RayCaster.render(RayCaster.java:60)
at com.happyryan2.raycaster.utilities.Screen.paint(Screen.java:82)
...
关于此错误消息的令人困惑的部分是它说索引是8,大小是12 ; 8小于12,那么为什么当它显然不是时却说超出范围?
(这是在单线程程序中。)