我在NETBeBes中有一个标准的(非JavaFX)Maven Java项目。它应该做的第一件事是加载一个.fxml文件,但是我似乎找不到它使用
getClass().getResource()
.
这是不寻常的,因为这个项目是从一个标准的java项目导入的,它运行良好,没有错误。
主要方法如下:
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Main_PanelController controller = new Main_PanelController(this);
FXMLLoader loader = new FXMLLoader(getClass().getResource("Main_Panel.fxml"));
loader.setController(controller);
URL url = getClass().getResource("Main_Panel.fxml");
System.out.println("URL: " + url);
System.exit(0);
Parent root = loader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.getIcons().add(new Image(new FileInputStream(Paths.get("Pictures", "SBU Emblem.png").toFile())));
stage.setAlwaysOnTop(true);
stage.setTitle("Simple Knisley Citation Tool α 0.5");
stage.setResizable(false);
stage.show();
}
url总是返回为
null
.
&文件层次结构:
我有
System.out.println
作为测试方法,查看url对象是否返回为空。根据我所读到的一切
getClass().getResource()
它应该得到与调用类在同一个包中的任何对象,
Main_Panel.fxml
是。
下面是来自
target
文件夹后
Clean & Build
已使用命令运行
jar tf Simple-Knisley-0.5-Alpha-jackofall.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/protonmail/
com/protonmail/sarahszabo/
com/protonmail/sarahszabo/simpleknisley/
com/protonmail/sarahszabo/simpleknisley/core/
com/protonmail/sarahszabo/simpleknisley/core/CitationDiskManager.class
com/protonmail/sarahszabo/simpleknisley/core/Main_PanelController.class
com/protonmail/sarahszabo/simpleknisley/core/CitationGenerator$GeneratorType.class
com/protonmail/sarahszabo/simpleknisley/core/CitationGenerator.class
com/protonmail/sarahszabo/simpleknisley/core/Main.class
.netbeans_automatic_build
META-INF/maven/
META-INF/maven/com.protonmail.sarahszabo.simpleknisley/
META-INF/maven/com.protonmail.sarahszabo.simpleknisley/Simple-Knisley/
META-INF/maven/com.protonmail.sarahszabo.simpleknisley/Simple-Knisley/pom.xml
META-INF/maven/com.protonmail.sarahszabo.simpleknisley/Simple-Knisley/pom.properties
我在Kubtuu 18.04 Bionic Beaver上使用NETBeaS 8.2的Java8Y171