Intellij找不到.png [英] Intellij can't find .png
本文介绍了Intellij找不到.png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的intellij找不到本地的.png图像.
My intellij can't find local .png images.
private String craft = "craft.png";
ImageIcon ii = new ImageIcon(this.getClass().getResource(craft));
.png与Java文件位于同一目录中.我不明白为什么它不起作用.使用Maven构建,尝试了从资源到Java的交替,但还是没有运气:(
The .png is located in the same directory as the java files. I don't understand why it isn't working. Using maven build, tried alternating from resources to java, but still no luck :(
推荐答案
craft.png
必须放入src/main/resources
中,否则根据Maven规则不会将其复制到类路径中.有关更多详细信息,请参见此答案.
craft.png
must be placed into src/main/resources
, otherwise it will be not copied to the classpath according to the Maven rules. See this answer for more details.
您的代码也应更改为:
private String craft = "/craft.png";
这是示例工作项目.
这篇关于Intellij找不到.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文