相关疑难解决方法(0)

Java ImageIO.read(getClass().getResource()) 返回 null

线

andImg = ImageIO.read(getClass().getResource("gate_and.png"));
Run Code Online (Sandbox Code Playgroud)

失败

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!
Run Code Online (Sandbox Code Playgroud)

我正在使用 Eclipse,在 bin 文件夹下的导航视图中有文件 gate_and.png,表明该文件在构建路径中。

在包资源管理器视图中,我有

project/src/view/class  - This is the class that has the code above.
Run Code Online (Sandbox Code Playgroud)

project/images/gate_and.png
Run Code Online (Sandbox Code Playgroud)

我右键单击项目文件夹 > 构建路径 > 链接源以将图像文件夹添加为源,再次执行此操作会提供一个确认消息,表明图像已在源中。

我也尝试将gate_and.png 更改为images/gate_and.png 和/images/gate_and.png,但由于图像gate_and.png 在bin 文件夹中,我认为原始是正确的。

java ubuntu resources image

2
推荐指数
1
解决办法
9769
查看次数

标签 统计

image ×1

java ×1

resources ×1

ubuntu ×1