问题描述
我知道已经存在一些有关相对路径的问题,但是我一直无法让JavaFX FXML加载器从其自身以外的包中加载资源.
I know there have already been some questions about relative paths, but I Keep failing to get JavaFX FXML loader to load a resource from a package other than itself.
加载类位于软件包gui.controllers中,而fxml文件BarSheet.fxml
位于软件包gui.resources
中.我现在应该放什么:
The loading class is located in the package gui.controllers and the fxml file BarSheet.fxml
is located in the package gui.resources
.What should i now put in :
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("src/gui/resources/BarSheet.fxml"));
预先感谢
推荐答案
已解决:问题在于我的fxml文件包含一个错误,因此我不知道何时输入正确的路径,因为它仍然无法正常工作. .该路径应以/开头,以指示从根开始的路径,后跟packages/filename.因此,就我而言
SOLVED: The fault was in the fact that my fxml file contained an error so i didnt know when i entered the right path because it would still not work...The path should start with / to indicate the path starting from the root followed by packages/filename. So in my case
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("/gui/resources/BarSheet.fxml"));
这篇关于JavaFX:从其他程序包加载资源-NetBeans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!