I have the oddest problem, probably with a simple solution.
I have created and initialized a list and then proceeded to create 4 objects of the list's type. In the constructor of these they place themselves in the list. Or at least are supposed to. I always get an out of bound exception and I cant figure out why. I set the list to have a size of 402 (for all possible VK values) but in the console and debug it always says it has size 0, no matter how large or empty I set it too....
public class InputHandler implements KeyListener
{
public static List<Key> keyList = new ArrayList<Key>(KeyEvent.KEY_LAST);
public Key up = new Key(KeyEvent.VK_UP);
public Key down = new Key(KeyEvent.VK_DOWN);
public Key left = new Key(KeyEvent.VK_LEFT);
public Key right = new Key(KeyEvent.VK_RIGHT);
public class Key
{
public int keyCode;
public Key(int defaultCode)
{
this.keyCode = defaultCode;
keyList.add(keyCode,this);
}
public Key reMapKey(int newKey)
{
keyList.remove(keyCode);
keyList.set(newKey, this);
this.keyCode = newKey;
return this;
}
}
}
There is more to the code but I attempted to SSCCE it.
The only info of value from the console is this:
Exception in thread "RogueLoveMainThread" java.lang.IndexOutOfBoundsException: Index: 38, Size: 0
Much apologies for my stupidity