我正在编写一个简单的双棒射击游戏,当我创建菜单时,我在关闭游戏时注意到控制台中存在IOException。它并不总是发生,但大部分时间我关闭窗口。
java.io.IOException: closed
at javax.imageio.stream.ImageInputStreamImpl.checkClosed(Unknown Source)
at javax.imageio.stream.ImageInputStreamImpl.close(Unknown Source)
at javax.imageio.stream.FileCacheImageInputStream.close(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at shooter.main.gfx.ImageLoader.load(ImageLoader.java:14)
at shooter.main.Menu.render(Menu.java:17)
at shooter.main.Game.render(Game.java:154)
at shooter.main.Game.run(Game.java:200)
at java.lang.Thread.run(Unknown Source)
我正在使用此课程阅读BufferedImages:
public class ImageLoader {
public BufferedImage load(String path) {
try {
return ImageIO.read(getClass().getResource(path));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
导致错误的行:
title = game.getImageLoader().load("/gfx/title.png");
就我个人而言,我不确定为什么会发生这种情况,因为我之前已经在屏幕上绘制了图片而且我从未得到过例外。那里有谁能告诉我为什么会这样? MAybe我必须在关闭之前垃圾收集所有缓冲图像或类似的东西吗?