IOException when changing from file to BufferedImage
2 answers
The root cause of your problem is best determined by examining the stacktrace for the exception.
As a temporary measure, replace these two lines with the following:
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;
}
to send some diagnostics to standard error. Run the modified application and publish the result.
Possible reasons:
- Invalid file name,
- The file is not in the current application directory,
- The file is not readable by the application due to operating system access controls,
- The file is readable, but something is wrong in its format,
- etc.
+6
source to share
Is there a file? Are you reading from an unexpected directory by accident?
Try File.exists () and / or File. CanRead ()
+2
source to share