有时,当我的Java应用程序在Netbeans7.4中运行时,它会生成一些错误消息,如下所示:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:470)
at javax.swing.plaf.basic.BasicTabbedPaneUI.getTextViewForTab(BasicTabbedPaneUI.java:1706)
at javax.swing.plaf.basic.BasicTabbedPaneUI.calculateTabHeight(BasicTabbedPaneUI.java:1717)
at javax.swing.plaf.basic.BasicTabbedPaneUI.calculateMaxTabHeight(BasicTabbedPaneUI.java:1742)
at javax.swing.plaf.metal.MetalTabbedPaneUI.calculateMaxTabHeight(MetalTabbedPaneUI.java:1147)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.calculateTabRects(BasicTabbedPaneUI.java:2586)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.calculateLayoutInfo(BasicTabbedPaneUI.java:2512)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.layoutContainer(BasicTabbedPaneUI.java:2407)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:1688)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validate(Container.java:1623)
at javax.swing.RepaintManager$2.run(RepaintManager.java:691)
at javax.swing.RepaintManager$2.run(RepaintManager.java:689)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:688)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1676)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:470)
at javax.swing.plaf.basic.BasicTabbedPaneUI.getTextViewForTab(BasicTabbedPaneUI.java:1706)
at javax.swing.plaf.basic.BasicTabbedPaneUI.calculateTabHeight(BasicTabbedPaneUI.java:1717)
at javax.swing.plaf.basic.BasicTabbedPaneUI.calculateMaxTabHeight(BasicTabbedPaneUI.java:1742)
at javax.swing.plaf.metal.MetalTabbedPaneUI.calculateMaxTabHeight(MetalTabbedPaneUI.java:1147)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.calculateTabRects(BasicTabbedPaneUI.java:2586)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.calculateLayoutInfo(BasicTabbedPaneUI.java:2512)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.layoutContainer(BasicTabbedPaneUI.java:2407)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:1688)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validate(Container.java:1623)
at javax.swing.RepaintManager$2.run(RepaintManager.java:691)
at javax.swing.RepaintManager$2.run(RepaintManager.java:689)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:688)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1676)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
但它没有显示我的代码中的哪一行导致错误,应用程序似乎执行正常,我该怎么办?这只会在某个时间发生,如果我再次运行它,可能会也可能没有相同的错误。
答案 0 :(得分:1)
接近BasicTabbedPaneUI源代码中的那行代码,getTextViewForTab()唯一能做的就是将一个名为HtmlViews的元素从一个名为tabIndex的变量的值中获取。您的代码在某些时候是否从标签视图中删除了标签?如果是这样,我的猜测是,它会以一种不更新UI的方式实现,其中一个选项卡现在已经消失,这就是导致此错误的原因。