# [java] java internal java.lang.ArrayIndexOutOfBoundsException

## Recommended Posts

Kaze    948
How do I find the cause of a exception that was created and caught entirely within the java libraries.

[code]
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.text.BoxView.getOffset(Unknown Source)
at javax.swing.text.BoxView.childAllocation(Unknown Source)
at javax.swing.text.CompositeView.getChildAllocation(Unknown Source)
at javax.swing.text.BoxView.getChildAllocation(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(Unknown Source) at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
[/code]

##### Share on other sites
VildNinja    789
Most likely it's because you're manipulating some text, while an other thread is trying to reach it. Is your program multithreaded?

The stack says "EventDispatchThread" so it's most likely caused by some event being thrown.

Otherwise try with a few System.out.println this is generally considered ugly code, but it can be quite useful, if you got the tiniest idea of where the bug is located.

But generally it's difficult to say any more, with this few informations.

##### Share on other sites
Kaze    948
[quote name='VildNinja' timestamp='1311105593' post='4837590']
Most likely it's because you're manipulating some text, while an other thread is trying to reach it. Is your program multithreaded?
[/quote]
I'm not using any multithreading unless swing is doing it in the background.

[quote name='VildNinja' timestamp='1311105593' post='4837590']
The stack says "EventDispatchThread" so it's most likely caused by some event being thrown.
Otherwise try with a few System.out.println this is generally considered ugly code, but it can be quite useful, if you got the tiniest idea of where the bug is located.
[/quote]
I already have a logger and put try catches on events I suspected might be the problem but haven't got anything yet.

[quote name='VildNinja' timestamp='1311105593' post='4837590']
But generally it's difficult to say any more, with this few informations.
[/quote]
I don't have much more information, this bug seems to happen randomly.

##### Share on other sites
VildNinja    789
Yes swing does it behind your back.. does it happen at random, when you click some thing, or does it just happen at random?

Do your program use any kind of text verification?
Do you have a game loop, that repeats some code?
Do you do any thing in the thread that opens the window (calls setVisible) after you've opened the window?

Edit: if yes, please post the code

##### Share on other sites
Kaze    948
I don't think my project has any of that though I think you are right about it being a multithreading issue due to how randomly it happens.

VildNinja    789

##### Share on other sites
Kaze    948
[quote name='VildNinja' timestamp='1311110568' post='4837631']
[/quote]

At the moment very little, I'm just working on a user interface for editing some files that will eventually be a game maker like program.

##### Share on other sites
VildNinja    789
Ok, the error should be where you are entering some text.

I think I need to see the code for every where the user can give any input, and the code where you create the window..

Also what swing components are you using?

##### Share on other sites
Kaze    948
Since this is a commercial project I can't post large sections of the code. Entering text doesn't seem to correlate with the error occurring since it often happens at start up. I am using most of the basic swing components.

##### Share on other sites
j-locke    945
In absence of code, maybe an approach could be to remove one or a group of the swing controls at a time. You could delete them then undo the change after a test run assuming your ide has undo (and hopefully for a commercial venture you have some source control going on to further protect from any crazily bad outcomes).