从其他软件包中找到fxml文件

时间:2020-01-09 16:13:00

标签: javafx fxml fxmlloader

尝试从位于其他程序包中的控制器打开fxml文件时,我遇到了“去掉头发”类型的麻烦。包的结构如下:

控制器名称= LocationController 控制器程序包= src/com/yas/prayertimeconfig/location/java

FXML文件名= AvailableAddresses.fxml FXML文件包= src/com/yas/prayertimeconfig/availableaddresses/java

我用来从LocationController中打开fxml文件的代码如下:

@FXML void btnFindAddress_Click(ActionEvent event) throws IOException {

        try{            
            Parent root1 = FXMLLoader.load(getClass().getResource("/src/com/yas/prayertimeconfig/availableaddresses/java/AvailableAddresses.fxml"));
            Stage stage = new Stage();
            stage.setTitle("Available Addresses");
            stage.setScene(new Scene(root1));
            stage.show();
        } catch (Exception e) {
            System.out.println(e);
        }


    }

我不断得到:

java.lang.NullPointerException: Location is required.

我尝试了所有使用方法:

getClass().getResource()

getClass().getClassLoader().getResource()

没有喜悦。

请帮助!

0 个答案:

没有答案
相关问题