Search code examples
javagraphicstextures

Changed an image but it does not appear in my java game


i am trying to make my first java game. I am currently messing around with adding textures but i have ran into a problem.

I can load an image an it i will appear in game but if i make a change to the image in photoshop and then re run the game the image will not have changed.

also if i made a copy of the image and then changed the path to point to that image the game throws and error.

public static Render floor = loadBitmap("/textures/floor.png");

this piece of code points to where the image is stored and the game will run but if i edit the image in photoshop nothing changes in the game.

public static Render floor = loadBitmap("/textures/floorp.png");

If i change the path to another image in the same folder i get this error.

Exception in thread "Thread-2" java.lang.ExceptionInInitializerError
at com.mime.minefront.graphics.Render3D.floor(Render3D.java:42)
at com.mime.minefront.graphics.Screen.render(Screen.java:27)
at com.mime.minefront.Display.render(Display.java:144)
at com.mime.minefront.Display.run(Display.java:112)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: input == null!
at com.mime.minefront.graphics.Texture.loadBitmap(Texture.java:20)
at com.mime.minefront.graphics.Texture.<clinit>(Texture.java:8)
... 5 more
Caused by: java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1388)
at com.mime.minefront.graphics.Texture.loadBitmap(Texture.java:12)
... 6 more
BUILD SUCCESSFUL (total time: 1 second)

And this is the code i am using in my texture class.

package com.mime.minefront.graphics;

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class Texture {

public static Render floor = loadBitmap("/textures/floorp.png");

public static Render loadBitmap(String fileName) {
    try {
        BufferedImage image = ImageIO.read(Texture.class.getResource(fileName));
        int width = image.getWidth();
        int height = image.getHeight();
        Render result = new Render(width, height);
        image.getRGB(0, 0, width, height, result.pixels, 0, width);
        return result;
    } catch (Exception e) {
        System.out.println("CRASH!");
        throw new RuntimeException(e);

    }
}

}

Solution

  • It appears as though the path you are loading is within your application Jar file. It is likely that you are saving the image but not updating your Jar, so the changes are not propagating. This would also explain why floorp.png is not being found. Rebuild your application when you make changes to the image directory.