java.lang.ArrayIndexOutOfBoundsException: No such child: 0 in JMEDesktop.paint()


I am periodically, more or less randomly, getting the following stack trace on System.err:

    [java] Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 0

    [java]    at java.awt.Container.getComponent(

    [java]    at javax.swing.JComponent.rectangleIsObscured(

    [java]    at javax.swing.JComponent.paint(

    [java]    at javax.swing.JLayeredPane.paint(

    [java]    at com.jmex.awt.swingui.JMEDesktop$2.paint(Unknown Source)

    [java]    at javax.swing.JComponent._paintImmediately(

    [java]    at javax.swing.JComponent.paintImmediately(

    [java]    at javax.swing.RepaintManager.paintDirtyRegions(

    [java]    at javax.swing.SystemEventQueueUtilities$

    [java]    at java.awt.event.InvocationEvent.dispatch(

    [java]    at java.awt.EventQueue.dispatchEvent(

    [java]    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(

    [java]    at java.awt.EventDispatchThread.pumpEventsForHierarchy(

    [java]    at java.awt.EventDispatchThread.pumpEvents(

    [java]    at java.awt.EventDispatchThread.pumpEvents(

    [java]    at

I guess it is a bug of some kind in JMEDesktop, but I don't know enough about Swing/AWT to try to troubleshoot it on my own. One thing that we're doing with JMEDesktop that I suppose could be a bit iffy include:

if ( displayTweak ) {



else {



in order to toggle the display of a particular frame. It's hard to tell exactly, but I have a feeling that the exception happens most often when the tweakFrame is hidden (removed), and it then means that the part of another JMEDesktop frame that lies underneath it is cut out, showing the 3D background.

Does anybody have an idea of how to solve this?

This might not be the solution, but in any case you should make sure that any adding or removing or for that matter any other type of Swing methods are called from the Swing thread only. Swing has a utility class for this (SwingUtilities) with methods invokeAndWait and invokeLater. For an example of how to do this, uses them as well. This is not a jME issue, it's how Swing must be used in any application, as specified in the documentation of Swing.

If the exception occurs right at the moment when you remove the tweakFrame, and you are currently calling these methods from the jME thread, this is likely the cause.

Thanks for the tip! After a couple of initial tests, that seems to have helped. Can't be sure yet, but I used to get a couple of those exceptions in a test run of a few minutes, so it looks good.  :slight_smile: