• JavaFX引入资源问题


    描述
    - 使用javafx 引入资源的时候 抛出异常 在swing引入资源 采取相对路径即可,而javafx不是

        ImageView imageNode = (ImageView) root.lookup("#myimage");
        imageNode.setImage(new Image("resouces/标题画面.jpg"));
    • image 路径下 查看源代码发现是
     private static String validateUrl(final String url) {
            if (url == null) {
                throw new NullPointerException("URL must not be null");
            }
    
            if (url.trim().isEmpty()) {
                throw new IllegalArgumentException("URL must not be empty");
            }
    
            try {
                if (!URL_QUICKMATCH.matcher(url).matches()) {
                    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                    URL resource;
                    if (url.charAt(0) == '/') {
                        resource = contextClassLoader.getResource(url.substring(1));
                    } else {
                        resource = contextClassLoader.getResource(url);
                    }
                    if (resource == null) {
                        throw new IllegalArgumentException("Invalid URL or resource not found");
                    }
                    return resource.toString();
                }
                // Use URL constructor for validation
                return new URL(url).toString();
    • 原来是classloder下载入的,那么我们只需要从bin下导入文件即可

    Paste_Image.png

  • 相关阅读:
    js 自定义属性
    js innerText、textContent、innerHTML的区别和各自用法
    js 的常用选择器
    js Array属性和用法
    js---String对象
    iframe自适应高度js
    thinkphp 的save()不能更新数据解决办法
    转义字符
    获取客户端真实ip
    thinkphp条件查询和模糊查询的一些方法
  • 原文地址:https://www.cnblogs.com/dgwblog/p/7635199.html
Copyright © 2020-2023  润新知