即使 url 正确,javafx 错误

javafx error even though url is correct

即使给定的路径正确并且图像显示在场景生成器中,它在 运行 应用程序时抛出错误。

Executing C:\Users3240\Documents\NetBeansProjects\UI\dist\run547088191\UI.jar using platform C:\Program Files (x86)\Java\jdk1.8.0_40\jre/bin/java
Device "Intel(R) G41 Express Chipset" (\.\DISPLAY1) initialization failed : 
WARNING: bad driver version detected, device disabled. Please update your driver to at least version 8.15.10.2302
null/Images/home.png
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
    at javafx.scene.image.Image.validateUrl(Image.java:1091)
    ... 23 more
Exception running application ui.Main
Java Result: 1

我遇到了同样的问题

解决方案:

转到 java 控制器 class 并编写此代码

private Image image;

@FXML
ImageView imageview; // type your imageview fixid

    private void setImage(String url) {
    try {
        image = new Image(url);
        imageview.setImage(image);
    } catch (Exception e) {
        System.out.println(e);
    }

}