错误:未处理的异常类型 IOException。
File imgLoc = new File("player.png");
BufferedImage img = ImageIO.read(imgLoc);
如何从文件位置获取 bufferedImage?
错误:未处理的异常类型 IOException。
File imgLoc = new File("player.png");
BufferedImage img = ImageIO.read(imgLoc);
如何从文件位置获取 bufferedImage?
问题的原因最好通过检查异常的堆栈跟踪来确定。
作为临时措施,将这两行替换为以下内容:
File imgLoc = new File("player.png");
BufferedImage img;
try {
img = ImageIO.read(imgLoc);
} catch (IOException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace();
throw ex;
}
将一些诊断信息发送到标准错误。运行修改后的应用程序并发布结果输出。
可能的原因包括:
该文件是否存在?您是否偶然阅读了意外的目录?