0

I'm having some troubles to load images in javaFX from the controller.

I put some images in the src/ folder and even in a folder img/ but still getting "Invalid URL or resource not found".

My directory is like

src/
    package/
      javaFXcontroller.java
      img/
         image.png

So I'm doing Image img = new Image("./img/image.png");

But I can't retrieve the image "java.lang.IllegalArgumentException: Invalid URL or resource not found"

Thanks for your help

  • Try `new Image("/img/image.png")`. – Slaw Dec 28 '18 at 00:13
  • Thanks but It doesn't work either.. –  Dec 28 '18 at 00:15
  • Is the `src` directory marked as a resources directory by your IDE? Are you using a build tool such as Maven or Gradle? Make sure `image.png` is included in the build output and added to the classpath/modulepath at runtime. – Slaw Dec 28 '18 at 00:16
  • I'm not using Gradle or Maven unfortunalety. I just dragged images from my folder into the package of eclipse –  Dec 28 '18 at 00:18
  • Unfortunately, I'm not familiar with Eclipse. These questions may help you: https://stackoverflow.com/questions/7217228/ and https://stackoverflow.com/questions/27934796/ – Slaw Dec 28 '18 at 00:23
  • Thanks you @Slaw but I found what I wanted. For those who may encounter the same problem, just drag your images into the src/ folder directly with eclipse and then require your image with the path new Image("image.png"). –  Dec 28 '18 at 00:36
  • Consider posting an answer to your own question. – c0der Dec 28 '18 at 08:05

1 Answers1

0

For those who may encounter the same problem, just drag your images into the src/ folder directly with eclipse and then require your image with the path new Image("image.png").