エラー: 未処理の例外タイプ 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 を取得するにはどうすればよいですか?
問題の原因は、スタックトレースで例外を調べることによって最もよく判断できます。
一時的な措置として、これらの 2 行を次のように置き換えます。
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;
}
いくつかの診断を標準エラーに送信します。変更したアプリを実行し、結果の出力を投稿します。
考えられる原因は次のとおりです。
ファイルは存在しますか? 偶然、予期しないディレクトリから読み取っていませんか?
File.exists()および/またはFile.canRead( ) を試してください