本帖最后由 liuzhenjun_0722 于 2012-11-15 12:37:09 编辑 public ImageComponent()
{
//acquire the image
try
{
//我使用的工具是MyEclipse,此处需要读取一张图片,没有任何提示,直接打印出异常日志,要读取图片如何修改呢,请教各位
image = ImageIO.read(new File("blue-ball.gif"));
}
catch(IOException e)
{
e.printStackTrace();
}
}
报错如下:
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at exa7_6.ImageComponent.<init>(ImageTest.java:57)
at exa7_6.DrawFrame.<init>(ImageTest.java:40)
at exa7_6.ImageTest$1.run(ImageTest.java:24)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
------最佳解决方案--------------------------------------------------------
文件放路径是不是写错了,应该放在在项目下
------其他解决方案--------------------------------------------------------
文件读取错误有两个原因:一是路径,二是该图片不能识别。
楼主,先看看你的路径
------其他解决方案--------------------------------------------------------
应该检查一下你的路径
------其他解决方案--------------------------------------------------------
image = ImageIO.read(new File("blue-ball.gif"));
要么复制图片到你的项目下面,要么修改路径
------其他解决方案--------------------------------------------------------
+1