找不到java.lang.ArrayIndexOutOfBoundsException的问题

时间:2011-03-07 16:54:43

标签: java debugging exception exception-handling

我的应用程序有问题,有些时候在控制台中返回此错误,但我找不到原点(所有未知来源)。应用程序似乎在此错误后正常工作,但我想了解什么是附加...我该怎么办?

谢谢你,对不起我的英语!

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)

2 个答案:

答案 0 :(得分:12)

查看BasicListUI.updateLayoutState()的来源,只有在方法执行时显示的列表更改大小时才会发生这种情况。

最可能的原因是您正在event dispatch thread之外修改模型。这是一个严重的问题,因为它可能导致各种奇怪的行为,甚至是数据损坏。

要解决这些问题,请在需要从EDT外部操作模型时使用SwingUtilities.invokeLater()

答案 1 :(得分:1)

这种类型的错误有时是由更新GUI组件关闭引起的,当它应该在EDT上 时完成。

如果修改违反该原则的任何代码无法解决问题,我建议您尝试准备SSCCE&把它发布到帖子中。