Intellij无法找到.png [英] Intellij can't find .png

查看:96
本文介绍了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.

您的代码也应更改为:

私有字符串craft ="/craft.png";

这是示例工作项目.

这篇关于Intellij无法找到.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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