gpt4 book ai didi

java - 创建新阶段时抛出 ExceptionInInitializerError

转载 作者:行者123 更新时间:2023-12-01 09:57:31 25 4
gpt4 key购买 nike

我使用 swing JFrame 作为我的应用程序的 MainFrame。我有一个按钮应该创建一个新窗口。但它会在初始化时崩溃,我不知道为什么。

public class Dialog {
private Stage window;

public void display() {
window = new Stage(); //This is line 45. This is place where it crash
window.setMinWidth(350);
window.setMinHeight(500);
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Add new Stuff");
//more code here
}
}

这是整个异常错误

Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at javafx.stage.Window.<init>(Window.java:1179)
at javafx.stage.Stage.<init>(Stage.java:236)
at javafx.stage.Stage.<init>(Stage.java:224)
at main.Dialog.display(Dialog.java:45)
at main.MainFrame.jButtonAddZamActionPerformed(MainFrame.java:400)
at main.MainFrame.access$400(MainFrame.java:12)
at main.MainFrame$5.actionPerformed(MainFrame.java:227)
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:3324)
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:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:702)
at java.awt.EventQueue$3.run(EventQueue.java:696)
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:724)
at java.awt.EventQueue$4.run(EventQueue.java:722)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
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: This operation is permitted on the event thread only; currentThread = AWT-EventQueue-0
at com.sun.glass.ui.Application.checkEventThread(Application.java:443)
at com.sun.glass.ui.Screen.setEventHandler(Screen.java:245)
at com.sun.javafx.tk.quantum.QuantumToolkit.setScreenConfigurationListener(QuantumToolkit.java:674)
at javafx.stage.Screen.<clinit>(Screen.java:80)
... 43 more

有什么想法为什么会崩溃吗?谢谢

最佳答案

您可以在 swing 应用程序中使用 JavaFx 组件。我们为 ERP 应用程序执行了此操作,以显示带有 JavaFx 图表的仪表板。

enter image description here

初始化JavaFx相关代码应如下完成。

      Platform.runLater(new Runnable() {
@Override
public void run() {
initFX(fxPanel);
}
});

请参阅以下链接了解更多详情 https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm

关于java - 创建新阶段时抛出 ExceptionInInitializerError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37071189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com