描述
- 使用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下导入文件即可
网友评论