i have a problem with my application tha some times return this error in console, but i can't find the origin (all Unknown Source). THe application seems to work properly after this error, but i want to understand what appening... How i can do?
Thank you and sorry for my english!
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.ScrollPaneLayout.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.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
In order to avoid the java. lang. ArrayIndexOutOfBoundsException, you should always do the bound check before accessing array element e.g. Always remember that the array index starts at 0 and not 1 and an empty array has no element in it.
public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException. Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.
ArrayIndexOutofBoundsException is an unchecked exception. Therefore, the java compiler will not check if a given block of code throws it.
The StringIndexOutOfBoundsException is an unchecked exception in Java that occurs when an attempt is made to access the character of a string at an index which is either negative or greater than the length of the string.
Looking at the source of BasicListUI.updateLayoutState()
, this can only happen when the list being displayed changes size while the method executes.
The most likely reason is that you're modifying the model from outside the event dispatch thread. This is a serious problem, since it could result in all kinds of bizarre behaviour and even corrupt data.
To fix them problem, use SwingUtilities.invokeLater()
whenever you need to manipulate the model from outside the EDT.
This type of error is sometimes caused by updating GUI components off the EDT, when it should be done on the EDT.
If fixing any code that violates that principle does not solve the problem, I suggest you try to prepare an SSCCE & post it to the thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With