线
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 文件夹中,我认为原始是正确的。