在java中渲染图像

时间:2013-11-20 23:06:50

标签: java compiler-errors graphics3d

您好我正在尝试为刚开始创建的游戏添加纹理,并且我一直在收到错误,我只是想知道是否有人可以提供帮助。 错误指向此.java文件,代码如下。     包com.mime.minefront.graphics;

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

public class Texture {

public static Render floor = loadBitmap("\textures.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);

    }
}

}

错误列表是。

 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: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

1 个答案:

答案 0 :(得分:0)

JVM无法找到您指定的资源"\textures.textures/floor.png"

资源路径不应使用"\",而应使用"/"代替绝对路径。