My jar can't find my images in my game but in the ide (eclipse) works just fine

16 Views Asked by At

so my jar can't find the images in my program but they are found by the IDE here is the error message. I also went into the jar and they are in the jar itself , the images are all there

     javax.imageio.IIOException: Can't read input file!
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1308)
    at tile.TileManager.getTileImage(TileManager.java:53)
    at tile.TileManager.<init>(TileManager.java:35)
    at Main.GamePanel.<init>(GamePanel.java:44)
    at Main.DriverMain.main(DriverMain.java:27)

here is the code that makes the images

                idle = ImageIO.read(new File("sprites/player/mario_idle.gif"));
        walk1 = ImageIO.read(new File("sprites/player/mario_walk1.gif"));
        walk2 = ImageIO.read(new File("sprite/player/mario_walk2.gif"));

I also tried

idle = ImageIO.read(getClass().getResourceAsStream("sprites/player/mario_idle.gif"));
walk1 = ImageIO.read(getClass().getResourceAsStream("sprites/player/mario_walk1.gif"));
walk2 = ImageIO.read(getClass().getResourceAsStream("sprite/player/mario_walk2.gif"));

but I get a null pointer exception ^

my file structure are as follows

project folder > src > packages( entity , main, sprites , tile) > in spites are 2 folders player and map which houses the png's or gifs

again if I zip the jar and look inside it I can see the sprites folder and when i open it all the images are there

I tried having the images in an upper package "res" outside of src and it still gave me the same thing but this time the images where not inside the jar , therefore I took it as it should be in src

I appreciate any help

0

There are 0 best solutions below