1.在maven项目中一定要把资源文件必须放在resources文件夹下,并在idea中将resource设置为资源类型。
2.获取资源的写法有一下两种

//        Parent root = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/sample4/firstStage.fxml"));
        Parent root = FXMLLoader.load(this.getClass().getResource("/fxml/sample4/firstStage.fxml"));

3.遇到的问题是

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: Location is required.

4.如果是简单的java项目则放在code和resource放在个文件下是没有问题的

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄