zoukankan      html  css  js  c++  java
  • getResource的两种用法

    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.遇到的问题是

    	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放在个文件下是没有问题的

  • 相关阅读:
    爬虫入门(五)
    爬虫入门(四)
    爬虫入门(三)
    爬虫入门(二)
    爬虫入门(一)
    openpyxl的简单使用
    ansible(三)
    ansible(二)
    ansible(一)
    CF Global Round 10-F
  • 原文地址:https://www.cnblogs.com/mumian2/p/10743911.html
Copyright © 2011-2022 走看看