0

There is a resource (PNG image) inside the folder /resources/images/.

However, when I execute the following code I get an error, because the URL is null.

URL url = Test.class.getResource("/resources/images/icone.png");

However, when I debug the code it seems that the parameter "/resources/images/icone.png" is not passed at all, because Eclipse says it is null, as you can see on the image below:

parameter is null

I've searched a lot through the internet and I can't find an answer. Please, anyone has an advice?

jguilhermemv
  • 769
  • 3
  • 11
  • 28
  • 3
    Where is your resources folder relative to your class files? – Hovercraft Full Of Eels Jun 07 '16 at 21:43
  • Did you try `getResource("/images/icone.png")`? – OneCricketeer Jun 07 '16 at 21:44
  • 3
    getResource() doesn't load from folders. It loads from the classpath. You need to tell us what your classpath is, and where in the classpath the image is located. – JB Nizet Jun 07 '16 at 21:45
  • To add to what @JBNizet said, you would have to put the image in your drawable folder then call `getResource(R.drawable.YourImage);` – Sammy T Jun 07 '16 at 21:59
  • The `name` variable isn't null. It just appears this way, because, well, [because the way Eclipse works](http://stackoverflow.com/questions/11451558/why-debugging-jdk-libraries-in-eclipse-i-cant-see-local-variables-values). I'd advice you to use a [better IDE](https://www.jetbrains.com/idea/). – Erik Pragt Jun 07 '16 at 22:44
  • @HovercraftFullOfEels the project structure is as you can see below: - project - src (source folder) - classes are here - test (source folder) - resources (not a source folder) - images (images are here) As you can see, my classpath is the src folder + test folder + maven libraries – jguilhermemv Jun 08 '16 at 11:24

1 Answers1

0

The problem was that the resources folder wasn't a source folder.

To fix it I added the resources folder as a source folder and changed the image path to images/icone.png.

jguilhermemv
  • 769
  • 3
  • 11
  • 28