[英]read and jlabel set icon a image with different extension .001
File file = new File("C:\\registro_sql\\Imagens\\Livro02\\0000\\000011.001");
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(file);
Icon icon = (Icon) bufferedImage;
lblImageIcon.setIcon(icon);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "ERRO!");
}
錯誤:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at certidoesOrganizado.executor.main(executor.java:6)
我有一些擴展名為.001,.002,.003的文件,但是這些文件只是圖像,但是由於另一個軟件使用它們,因此我無法重命名該文件,但是我想使用Java來顯示該圖像文件,因為BufferedImage沒有顯示任何內容,它只是重新調諧錯誤
該錯誤與問題中的代碼無關,因為該錯誤表明IOException
具有try/catch
塊。 該錯誤可能是由未顯示的代碼引起的。
另外這句話
Icon icon = (Icon) bufferedImage;
由於BufferedImage
不是Icon
類型,將導致ClassCastException
。
更換
lblImageIcon.setIcon(icon);
與
lblImageIcon.setIcon(new ImageIcon(bufferedImage));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.