0

Im trying to use an imageView in an anchor pane. Im getting an Invalid URL or resource not found but im not sure why as the resource is in the folder I listed and I used eclipse Copy Qualified Name button so im not sure why it would be invalid. The package its contained in is in the src folder as well. Any help on this would be appreciated.

    @FXML AnchorPane pane;
    @FXML Label GameTitle;
    @FXML Label Categ1;
    @FXML Label Categ2;
    @FXML Label Categ3;
    @FXML Label DescLabel;
    @FXML ImageView gameIcon;
    public void updateInfo() {
        GameTitle.setText("Title");
        Categ1.setText("Category");
        Categ2.setText("Category");
        Categ3.setText("Category");
        DescLabel.setText("Temp Text");
        
        Image icon = new Image("../TempGameData/icon.jpg");
        gameIcon.setImage(icon);
    }

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml@18.0.1/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857) at javafx.fxml@18.0.1/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724) at javafx.base@18.0.1/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at javafx.base@18.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234) at javafx.base@18.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at javafx.base@18.0.1/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at javafx.base@18.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at javafx.base@18.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at javafx.base@18.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at javafx.base@18.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at javafx.base@18.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at javafx.base@18.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at javafx.base@18.0.1/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at javafx.base@18.0.1/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at javafx.base@18.0.1/javafx.event.Event.fireEvent(Event.java:198) at javafx.graphics@18.0.1/javafx.scene.Node.fireEvent(Node.java:8797) at javafx.controls@18.0.1/javafx.scene.control.Button.fire(Button.java:203) at javafx.controls@18.0.1/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208) at javafx.controls@18.0.1/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274) at javafx.base@18.0.1/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247) at javafx.base@18.0.1/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at javafx.base@18.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234) at javafx.base@18.0.1/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at javafx.base@18.0.1/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at javafx.base@18.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at javafx.base@18.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at javafx.base@18.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at javafx.base@18.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at javafx.base@18.0.1/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at javafx.base@18.0.1/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at javafx.base@18.0.1/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at javafx.base@18.0.1/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.base@18.0.1/javafx.event.Event.fireEvent(Event.java:198) at javafx.graphics@18.0.1/javafx.scene.Scene$MouseHandler.process(Scene.java:3881) at javafx.graphics@18.0.1/javafx.scene.Scene.processMouseEvent(Scene.java:1874) at javafx.graphics@18.0.1/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607) at javafx.graphics@18.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411) at javafx.graphics@18.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at javafx.graphics@18.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450) at javafx.graphics@18.0.1/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424) at javafx.graphics@18.0.1/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449) at javafx.graphics@18.0.1/com.sun.glass.ui.View.handleMouseEvent(View.java:551) at javafx.graphics@18.0.1/com.sun.glass.ui.View.notifyMouse(View.java:937) at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at javafx.base@18.0.1/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275) at javafx.fxml@18.0.1/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84) at javafx.fxml@18.0.1/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1852) ... 46 more Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found at javafx.graphics@18.0.1/javafx.scene.image.Image.validateUrl(Image.java:1135) at javafx.graphics@18.0.1/javafx.scene.image.Image.(Image.java:625) at DoubleTap/application.gameDisplayController.updateInfo(gameDisplayController.java:48) at DoubleTap/application.MainController.showGameInfo(MainController.java:26) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ... 53 more Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found at javafx.graphics@18.0.1/javafx.scene.image.Image.validateUrl(Image.java:1120) ... 57 more

  • Does this answer your question? [Define a relative path of image in Java FX](https://stackoverflow.com/questions/27446360/define-a-relative-path-of-image-in-java-fx) – Giovanni Contreras May 22 '22 at 17:29
  • @GiovanniContreras That solved my exception error but the image is still not displaying. Im now using `Image icon = new Image("file:TempGameData/icon.jpg");` which again solves the issue of the exception but it just leaves an empty space where the image should be. – Charles Urban May 22 '22 at 17:40
  • that image needs an `ImageView` container imageview has a constructor wich need an Image object as argument . And , finally , ImageView , as any other node , needs to be child of another node – Giovanni Contreras May 22 '22 at 18:14
  • 1
    The accepted answer to the question linked in the comments is completely wrong. You are loading the image from a resource, not from a file. – James_D May 22 '22 at 18:53
  • @James_D is right . please follow the answer marked as duplicate – Giovanni Contreras May 22 '22 at 19:19

0 Answers0