Java 7 Swing Applet在SortingFocusTraversalPolicy类中因StackOverflow错误而失败

时间:2014-01-30 11:31:39

标签: java swing applet

从Java 7开始,他们在SortingFocusTraversalPolicy类中添加了一个名为getComponentDownCycle的新方法。现在我一次又一次出现StachOverflow错误。 这是stach追踪:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.qwe.rty.swing.container.bootstrap.AppletBootstrap.bgInit(AppletBootstrap.java:291)
    at com.qwe.rty.swing.container.bootstrap.AppletBootstrap.access$1000(AppletBootstrap.java:46)
    at com.qwe.rty.swing.container.bootstrap.AppletBootstrap$BgInitThread$1.run(AppletBootstrap.java:715)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.qwe.rty.swing.container.bootstrap.AppletBootstrap$BgInitThread.run(AppletBootstrap.java:542)
Caused by: java.lang.reflect.InvocationTargetException
    at java.awt.EventQueue.invokeAndWait(Unknown Source)
    at java.awt.EventQueue.invokeAndWait(Unknown Source)
    at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
    at com.qwe.rty.swing.container.bootstrap.AppletBootstrap.bgInit(AppletBootstrap.java:212)
    ... 4 more
Caused by: java.lang.StackOverflowError
    at sun.awt.EmbeddedFrame.getParent(Unknown Source)
    at javax.swing.LayoutComparator.compare(Unknown Source)
    at javax.swing.LayoutComparator.compare(Unknown Source)
    at java.util.TimSort.countRunAndMakeAscending(Unknown Source)
    at java.util.TimSort.sort(Unknown Source)
    at java.util.TimSort.sort(Unknown Source)
    at java.util.Arrays.sort(Unknown Source)
    at java.util.Collections.sort(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(Unknown Source)
    at javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)...

似乎jre在尝试获得聚焦组件时进入无限递归。 有线索吗?

1 个答案:

答案 0 :(得分:1)

使用不带javax.swing.SwingUtilities.invokeAndWait(未知来源)的SwingUtilities.invokeLater()。它将解决这个问题。