【问题标题】:Array of BufferedImage instances: IIOExceptionBufferedImage 实例数组:IIOException
【发布时间】:2014-05-07 12:51:18
【问题描述】:

我正在制作一个菜单,使用awt.Graphics,当它绘制图片时它给了我一个奇怪的IIOException。是因为程序找不到图像吗?这是我的代码的使用方式。

public static BufferedImage[] img;

//this is where img[] gets initialized
for (int j = 0; j < worlds.length; j++) { //say worlds is about 3 or so
    String tmp = worlds.get(j);
    tmp = tmp.replace(".WORLD", "");
    img[j] = ImageIO.read(new File("C:\Users\Bryce\Desktop\" + tmp + ".png"));
}


//this is where it gets drawn
for (int i = 0; i < worlds.size(); i++) {
    String tmp = worlds.get(i);
    tmp = tmp.replace(".WORLD", "");
    try {
        for (int j = 0; j < worlds.size(); j++) {
            img[j] = ImageIO.read(new File("C:\Users\Bryce\Desktop\" + tmp + ".png"));
            g.drawImage(img[j], x + 10, y + (ySpace * i), 32, 32, null);
        }
    } catch(Exception ex) {
        ex.printStackTrace();
    }
}

它不断给我以下错误信息:

javax.imageio.IIOException: Can't read input file!

有什么建议吗?

【问题讨论】:

    标签: java file-io awt bufferedimage ioexception


    【解决方案1】:

    我实际上已经意识到我犯了一个愚蠢的错误,但它不知何故溜走了我的视线。我忘了告诉 BufferedImage[] 有多大

    img = new BufferedImage[worlds.size()];
    

    现在可以了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多