Search code examples
cssimagejavafxfxml

javafx error even though url is correct


Even though the path given is correct & image is displaying in scene builder, it is throwing error while running the application.

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

Solution

  • I had the same problem

    Solution:

    go to java controller class and write this code

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