0

I've looked at many questions similar to this and several threads with this topic. I can't figure out what's going on so I'm trying to ask for myself. I have read about having your resources folder inside of your src folder, in order to compile with the jar, also about using the folder as a source folder and removing the "/resources" part of your file path, these things seem to make sense to me but I'm still having my issue. Without having my folder used as source, or anything like that it's just a regular folder in my eclipse, and my attempt at correctly loading images would be,

dollsEyes = ImageIO.read(new File("resources/Enviroment/Plants/Dolls_Eyes.png"));  

inside of a try/catch block, then drawing the image with double buffering using Graphics and Graphics2D, things work fine until I try to compile to a jar, depending on what I'm trying it will either just not open, and I look inside with 7zip and I have my resources within the JAR, or it opens but just gives a white screen usually that's when there is nothing in my JAR.

I can post any code requested, I'm just not sure what other information is needed.

Trying with my resources just moved into my src folder, seemed to be the easiest way, gives an error when I'm trying to get the size of an image for setting a width and height for a sprite, a null pointer exception, my image is null.

  • You want to use https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#getResourceAsStream-java.lang.String- when getting resources from a jar. – Vojtěch Kaiser Sep 05 '18 at 06:52
  • 1
    getClass().getResourceAsStream? Over (new File())? – 4pricot_3ae Sep 05 '18 at 07:07
  • Okay so now nothing opens anymore, even in Eclipse, I even literally reversed every change I made and nothing will open and there are no errors, hovering over the run icon will say the program is running. – 4pricot_3ae Sep 05 '18 at 08:08
  • Take a look at this answer https://stackoverflow.com/a/15353743/1356924 (or ones around it depending on what exactly do you want to do). – Vojtěch Kaiser Sep 05 '18 at 08:24

0 Answers0