java - IndexOutOfBoundsException when removing ArrayList element -
i have code right here (using lwjgl should moot) try , pause game when pressing esc key. use arraylist keys keep track of pressed , isn't.
public list<integer> keys = new arraylist<integer>(); public void get() { if (iskeydown(key_escape) && !keys.contains(key_escape)) { keys.add(key_escape); keyescape(); } } public void rem() { if (!iskeydown(key_escape) && keys.contains(key_escape)) keys.remove(key_escape); } private void keyescape() { screen.paused ^= true; }
this called loop, get()
, rem()
1 right after in loop, in order. gives me awesome java.lang.indexoutofboundsexception: index: 1, size: 1
@ keys.remove(key_escape);
when let go of esc.
anyone have insight share?
what value of key_escape?
it might int value 1 instead of removing object value, remove object @ position 1 apparently not exist.
Comments
Post a Comment