Getting IllegalSrgumentException: input==null. When trying to load an image

孤人 提交于 2019-12-25 02:39:33

问题


i am trying to load an image to be used as a texture and i keep getting input==null errors; This is my code where i am trying to load the image and where most of the errors are pointing to.

package com.mime.minefront.graphics;

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

public class Texture {

public static Render floor = loadBitmap("/C:\\Users\\Danny\\Documents\\NetBeansProjects\\MyFirstgame\\src\\res\\textures\\floor.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);

    }
}

}

and the errors i am getting are as followed.

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:28)
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:19)
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:11)
... 6 more
BUILD SUCCESSFUL (total time: 4 seconds)

Please help

来源:https://stackoverflow.com/questions/20120322/getting-illegalsrgumentexception-input-null-when-trying-to-load-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!