我在 Greenfoot 为一个学校项目编程,我不断收到这个错误:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at Speler.act(Speler.java:60)
at greenfoot.core.Simulation.actActor(Simulation.java:583)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:541)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
通过此代码:
if (Greenfoot.isKeyDown("s"))
{
int wapenID;
if(schietTimer < 1)
{
if(richting != null)
{
if(gebruiktWapen != -1)
{
{
getWorld().addObject(new Kogel(richting), getX(), getY());
schietTimer = 30;
wapenLijst.get(gebruiktWapen).schietKogel();
System.out.println(wapenLijst.size());
if(wapenLijst.get(gebruiktWapen).hoeveelKogels() == 0)
{
gebruiktWapen++;
}
}
}
else
{
if(wapenLijst.size() > 0)
{
gebruiktWapen ++;
}
}
}
}
}
到目前为止,我似乎无法找到错误,因为我做了一些检查来检查索引。谁能帮我解决这个问题?