Slick Forums

IndexOutOfBoundsException inside TWL code
Page 1 of 1

Author:  stillwind [ Sat Jun 22, 2013 9:12 pm ]
Post subject:  IndexOutOfBoundsException inside TWL code

Hi Matthias,

I have a weird error, and it's very hard to replicate because it only happens occasionally. Maybe once every week (and I'm running my program a lot as I'm still developing it). It happens during the first few seconds of running, perhaps even on the first run through. I have some error trapping in place for serious errors, but after this happens once, it doesn't repeat and it appears the problem corrects itself, so I'd rather not abort the program.

So I'm wondering if you can make any suggestions, is this something I'm doing in a widget somewhere that is causing this error? Or can I safely trap this particular exception and do something different with it?

I'm pasting the place it's caught in the mainLoop() method (that I borrowed from your examples way back, so I hope it looks kinda familiar to you, plus the stack trace after this:

Thanks a lot for any suggestions

root = new RootPane();
renderer = new LWJGLRenderer();
gui = new GUI(root, renderer);


while (!Display.isCloseRequested() && !closeRequested) {


   try {
   } catch (Exception e) {
      resourceManager.log(LOG_TYPE.error, this, "KeepYaBeat.mainLoop: uncaught error "+e.getMessage());

SEVERE 22-jun-2013 13:11 39 KeepYaBeat.mainLoop: uncaught error Index: 1, Size: 0
STDERR 22-jun-2013 13:11 40 java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
STDERR 22-jun-2013 13:11 41    at java.util.ArrayList.RangeCheck(
STDERR 22-jun-2013 13:11 42    at java.util.ArrayList.get(
STDERR 22-jun-2013 13:11 43    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 44    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 45    at de.matthiasmann.twl.ScrollPane.validateLayout(
STDERR 22-jun-2013 13:11 46    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 47    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 48    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 49    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 50    at de.matthiasmann.twl.Widget.validateLayout(
STDERR 22-jun-2013 13:11 51    at de.matthiasmann.twl.GUI.validateLayout(
STDERR 22-jun-2013 13:11 52    at de.matthiasmann.twl.GUI.update(
STDERR 22-jun-2013 13:11 53    at com.stillwindsoftware.keepyabeat.KeepYaBeat.mainLoop(
STDERR 22-jun-2013 13:11 54    at
STDERR 22-jun-2013 13:11 55    at com.stillwindsoftware.keepyabeat.KeepYaBeat.main(

Author:  MatthiasM [ Sat Jun 22, 2013 9:56 pm ]
Post subject:  Re: IndexOutOfBoundsException inside TWL code

Do you have any code accessing TWL from another thread? (eg KryoNet callbacks etc)

Author:  stillwind [ Sat Jun 22, 2013 10:06 pm ]
Post subject:  Re: IndexOutOfBoundsException inside TWL code

Hmmm... short answer is, well, maybe... I'll have a good look at it, as I do some startup stuff in another thread which notifies when it completes, so I better first check it puts that in the gui thread.

I'll get back to you, thanks for the clue :wink:

Edit update:
Yup, my loadup code executes in another thread and when it completes it calls back, just as you suggest. And it immediately starts adding buttons to the root pane.
I guess I should put this all into a gui.invokeLater() call, that will cure it, right?

Author:  MatthiasM [ Sun Jun 23, 2013 4:42 am ]
Post subject:  Re: IndexOutOfBoundsException inside TWL code

Yep :)

Author:  stillwind [ Sun Jun 23, 2013 9:24 am ]
Post subject:  Re: IndexOutOfBoundsException inside TWL code

Since my last response I made the change. I've run it lots of times and I've seen no more problems with it. I'm pretty confident it's solved, particularly because your inspiration makes sense, and because you immediately knew what it must be.

Thanks for your great expertise!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group