ImageIO无法正确导入BufferedImage [英] ImageIO wont import BufferedImage correctly

查看:204
本文介绍了ImageIO无法正确导入BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引发错误-

线程"Thread-3"中的异常java.lang.IllegalArgumentException:输入== null! 在javax.imageio.ImageIO.read(未知来源)

Exception in thread "Thread-3" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source)

代码-

try {
        playerImage = ImageIO.read(Player.class
                .getResourceAsStream("/toon.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }

文件路径-

H:\ workspace \ Isaac \ resources \ toon.png

H:\workspace\Isaac\resources\toon.png

我已经对此进行了一些研究,但是没有一种解决方案真正适合我.有什么想法吗?

Ive researched this a bit but none of the solutions have really worked for me. any ideas?

推荐答案

如果Isaac是您的项目文件夹,则您的阅读方式应该可以使用.请检查目录resources是否为源文件夹(在eclipse中,该目录应具有Java包覆盖的文件夹图标),否则请右键单击该目录并转到Build path并选择Use as Source Folder

If Isaac is your project folder, then the way your are reading should work. Please check whether the directory resources is a source folder (in eclipse it should have an icon of a folder with an overlay of a java package), if not then right click on it and got to Build path and choose Use as Source Folder.

您的目录结构应如下所示:

Your directory structure should look something like this:

编译前

H:\workspace\Isaac
├───resources
│       toon.png
│
└───src
        Player.java

编译后

H:\workspace\Isaac
├───bin
│       Player.class
│       toon.png
│
├───resources
│       toon.png
│
└───src
        Player.java

getResourceAsStreambin中查找图像,而不在resources

getResourceAsStream looks for the image in bin and not in the one in resources

这篇关于ImageIO无法正确导入BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆