javafx错误,即使url是正确的

时间:2015-11-05 07:44:46

标签: css image javafx fxml

尽管给出的路径是正确的&图像在场景构建器中显示,运行应用程序时抛出错误。

Executing C:\Users\433240\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

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题

解决方案:

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

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);
    }

}