【发布时间】:2015-12-31 04:28:23
【问题描述】:
我对使用 JavaFX 和 FXML 非常非常陌生,我遇到了一些问题,我无法通过重复的 Google 搜索或在 Stack Exchange 上的搜索来解决.虽然其他人也有类似的问题,但我无法在我自己的项目中复制他们的解决方案。
现在,我主要只是尝试使用 FXML 测试 JavaFX 并感受一下……但是我什至无法加载它,因为 FXMLLoader 给了我以下错误。
javafx.fxml.LoadException: /C:/Users/Dylon/workspace/Convergence_titanExplorationModule/bin/com/test/fxml/ExplorationModuleUI.fxml
在 javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) at javafx.fxml.FXMLLoader.importClass(未知来源)在 javafx.fxml.FXMLLoader.processImport(未知来源)在 javafx.fxml.FXMLLoader.processProcessingInstruction(未知来源) 在 javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 在 javafx.fxml.FXMLLoader.loadImpl(未知来源)在 javafx.fxml.FXMLLoader.loadImpl(未知来源)在 javafx.fxml.FXMLLoader.loadImpl(未知来源)在 javafx.fxml.FXMLLoader.loadImpl(未知来源)在 javafx.fxml.FXMLLoader.loadImpl(未知来源)在 javafx.fxml.FXMLLoader.loadImpl(未知来源)在 javafx.fxml.FXMLLoader.load(未知来源)在 com.test.fxml.Main.start(Main.java:14) 在 com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(未知 来源)在 com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(未知 来源)在 com.sun.javafx.application.PlatformImpl.lambda$null$174(未知 源) 在 java.security.AccessController.doPrivileged(Native Method) 在 com.sun.javafx.application.PlatformImpl.lambda$runLater$175(未知 来源)在 com.sun.glass.ui.InvokeLaterDispatcher$Future.run(未知 来源)在 com.sun.glass.ui.win.WinApplication._runLoop(Native 方法)在 com.sun.glass.ui.win.WinApplication.lambda$null$149(来源不明) 在 java.lang.Thread.run(Unknown Source) 引起: java.lang.ClassNotFoundException 在 javafx.fxml.FXMLLoader.loadType(Unknown Source) ... 21 更多
现在,这是我正在使用的代码...
package com.test.fxml;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/com/test/fxml/ExplorationModuleUI.fxml"));
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
这是我的 FXML 文件,名为 ExplorationModuleUI.fxml...
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control*?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1">
<TOP>
<HBox>
<Button text = "test"/>
</HBox>
</TOP>
</BorderPane>
最后,这是我对文件夹的布局。
I can't post images yet so here's a link to one instead
非常感谢任何帮助。老实说,即使今晚挖掘了几个小时,我也无法弄清楚为什么它不起作用。我已经尝试过在此处和 Google 搜索中找到的其他解决方案,但还没有任何效果。如果您有任何问题,请随时提出,我会在早上尽快回复您。
【问题讨论】:
-
我建议以这个不错的教程中的应用程序为起点:code.makery.ch/library/javafx-8-tutorial
-
这看起来超级有用。我会检查一下。谢谢!
标签: java javafx fxml fxmlloader