0

I'm attempting to load an Image (leftStanding.png) using the following line:

spriteLeft[0] = new ImageIcon(getClass().getResource("resources/images/characters/" + characterType + "/leftStanding.png")).getImage();

where characterType is (at the moment) "mainCharacterMale". However, I'm getting a NullPointerException at that line. Using Netbeans, the file path for the image is ProjectFolder/src/resources/images/characters/mainCharacterMale/leftStanding.png. Oddly enough, earlier in the program I load a text file in a very similar fashion, with the path to that being ProjectFolder/src/resources/saveData/SaveFile1.txt, and there's no errors with that. Any help would be appreciated.

Avery Vine
  • 154
  • 10
  • Don't do it like this. Your resource folder should be along the src folder, not inside of it. And then you can get your image with `ImageIO.read(new File ("./resources/images/.../yourimage.png"))` – Coderino Javarino Jul 03 '16 at 18:33
  • Thanks for the tip. I switched it to that method, reading in the saveFile still works, but I'm getting the same error as before (in terms of reading in the image). Now the file path is `ProjectFolder/resources/images/characters/mainCharacterMale/leftStanding.png` – Avery Vine Jul 03 '16 at 19:12

0 Answers0