【发布时间】:2019-02-21 01:25:27
【问题描述】:
我的 javaFX jar 应用程序有问题。 当我在 IDEA 中编译我的项目时,它看起来像这样: enter image description here
但是当我构建 jar 应用程序时,在第一个窗口中按 AUTHORIZATION 后,
它不会打开下一个窗口。我使用 FXML 场景。
第一个窗口从 Main 类中的 start() 方法调用,其他窗口从控制器类调用。
主类中的方法。
public void start(Stage primaryStage) throws Exception {
Parent parent = FXMLLoader.load(getClass().getResource("Interface.fxml"));
Scene scene = new Scene(parent);
primaryStage.setScene(scene);
primaryStage.setTitle("Hello Client");
primaryStage.show();
}
还有一个控制器类:
@FXML
public void Autentification(ActionEvent actionEvent) throws Exception {
UserInform.AccauntName = name;
UserInform.UserName = name;
int intPort = Integer.parseInt(port);
messages.PrintMessage("Authentication started\n", Out);
ConnectionForUI.session.tryConnect(name, pass, host, intPort);
//Run next window
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../ClientField.fxml"));
Parent root = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("Client");
stage.setScene(new Scene(root));
stage.show();
}
Autentification 方法在我按下授权按钮时运行,并在此处运行下一个窗口。
我是 Java FX 的新手,如果您知道如何解决这个问题,我将不胜感激。
【问题讨论】:
-
尝试从命令行运行 Jar,看看它是否打印出任何错误消息。
-
是的,它写了 IllegalStateException。位置未设置,但我不知道如何解决这个问题
-
不要在
getResource中使用..。尝试资源的绝对路径。 -
您的 jar 找不到资源。 @Slaw 你比我快。 Idea 设置了导出 jar 时没有的相对路径。尝试使用实际 .jar 路径中的绝对路径/相对路径
-
但它看不到 FXML 的方式