0
点赞
收藏
分享

微信扫一扫

JavaFX引入资源问题

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

.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

  • 原来是classloder下载入的,那么我们只需要从bin下导入文件即可

JavaFX引入资源问题_查看源代码



举报

相关推荐

0 条评论