我尝试初始化CategoryAxis xAxis时得到java.lang.ExceptionInInitializerError

时间:2015-11-28 19:29:08

标签: java swing jpanel

我正在尝试将BarChart添加到现有的jPanel,但是得到以下错误:

Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at javafx.scene.chart.Axis.<init>(Axis.java:85)
at javafx.scene.chart.CategoryAxis.<init>(CategoryAxis.java:251)
at Gui.MainFrame.SetJFX(MainFrame.java:521)
at Gui.MainFrame.SetResTable(MainFrame.java:516)
at Gui.MainFrame.ExecuteButtonActionPerformed(MainFrame.java:490)
at Gui.MainFrame.access$200(MainFrame.java:49)
at Gui.MainFrame$3.actionPerformed(MainFrame.java:171)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:270)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:265)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:540)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:502)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 43 more

我不确定发生了什么,但我认为问题的原因是我尝试将 JFXpanel 添加到jpanel:

 521-->CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();

    xAxis.setLabel("Threads");
    yAxis.setLabel("Time to msec");

    BarChart<String, Number> BC = new BarChart<String, Number>(xAxis, yAxis);
    BC.setTitle("Time-Threads Compare");

    XYChart.Series series = new XYChart.Series();

    for (int i = 0; i < ThreadsNumOptions.size(); i++) {
        for (int j = 0; j < Results.size(); j++) {
            long sum = 0;
            long times = 0;

            if (ThreadsNumOptions.get(i).equals(Results.get(j).getMaxThreads())) {
                times++;
                sum += Results.get(j).getRawTime();
            }

            if(times>0){
                series.getData().add(new XYChart.Data(ThreadsNumOptions.get(i)+" thread(s)",new TimeKeeper().GetTime((int) (sum/times))));
            }
        }
    }

    Scene scene  = new Scene(BC,300,225);
    BC.getData().add(series);

    final JFXPanel fxPanel = new JFXPanel();
    fxPanel.setScene(scene);

    jPanelFX.add(fxPanel);

1 个答案:

答案 0 :(得分:1)

理想情况下,您发布Minimal, Complete, and Verifiable example

没有看到这个来源我不能确定,但​​它看起来非常像你试图在AWT线程中初始化JavaFX GUI组件。