gpt4 book ai didi

JavaFX - 应用程序 : Only main stage is shown from exported jar file while in Eclipse all dialogs are shown, 为什么会出现这种差异?

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:11 25 4
gpt4 key购买 nike

我正在尝试在 Windows 上测试我的 JavaFX 桌面应用程序并为其导出一个 jar 文件。我的Eclipse IDE版本:2019-03(4.11.0)

Java Class Controllers and FXML files in same directory

到目前为止,我在 Eclipse 中运行的代码,但是当我运行 jar 文件时,只弹出主阶段,下一个窗口不会显示,并且我在 cmd 上收到几条错误消息。

我尝试使用两个选项创建 jar 文件。从 eclipse 中标准“导出”,然后“JAR 文件”...

jar01

jar02

jar03

jar04

或者使用 Efxclipse - Ant Wizard。

build.fxbuild

两者的结果是相同的......

这是我的主类的摘录,它生成“主阶段”,这是唯一从 jar 运行的阶段:

private static Stage primary;

public void start(Stage primaryStage) {
try {


primary = primaryStage;
primaryStage.setTitle("Unicon Automation Tool");
primaryStage.setScene(new Scene(root, 278, 143));

primaryStage.setResizable(false);
primaryStage.setMaximized(false);

// primaryStage.resizableProperty().setValue(Boolean.FALSE);
primaryStage.show();

} catch (Exception e) {
e.printStackTrace();
}
}

这是来自一个 Controller 类的用于后续阶段的一些代码:

private static Stage mainMenu;

private void handleNextAction(ActionEvent event) {

Window owner = next.getScene().getWindow();

if (console.isSelected()) {

Main.goBack();
Main.setPresentationMode(0);
Test.test();

}

else if (ui.isSelected()) {
Main.goBack();
Main.setPresentationMode(1);

try {
Parent root = FXMLLoader.load(getClass().getResource("firstMenu.fxml"));

mainMenu = new Stage();

mainMenu.setTitle("Unicon Automation Tool");
mainMenu.setScene(new Scene(root,441, 218));

//mainMenu.resizableProperty().setValue(Boolean.FALSE);
mainMenu.setResizable(false);
mainMenu.setMaximized(false);
mainMenu.show();


} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}

else
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!", "You must select one of the options!");

}

预期应用程序的窗口会像在 Eclipse IDE 中一样显示,但在我运行 jar 文件后,只出现主阶段,单击“下一步”后,我收到此错误消息:

> Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java
.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader
.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Comp
ositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH
andlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH
andlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(C
ompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis
patcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat
chChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis
patcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat
chChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis
patcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat
chChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Bu
ttonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorS
kinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorS
kinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.h
andleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Comp
ositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH
andlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH
andlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(C
ompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis
patcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat
chChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis
patcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat
chChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis
patcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat
chChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotificatio
n.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotificatio
n.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEve
nt$358(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Quantum
Toolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Glas
sViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.ja
va:177)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 48 more
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.MainMenuController.handleNextAction(MainMenuController.ja
va:70)
... 58 more

最佳答案

我今天可以测试代码,@helospark 的评论是正确的答案。在匹配源代码中的 .fxml 文件的名称并导出 jar 文件后,应用程序按预期运行。但奇怪的是 Eclipse IDE 对大写“M”不敏感

关于JavaFX - 应用程序 : Only main stage is shown from exported jar file while in Eclipse all dialogs are shown, 为什么会出现这种差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58060365/

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