为什么这个 "new ImageIcon(getClass().getResource("files/icon.png")).getImage();"让我的程序不可见?

Why does this "new ImageIcon(getClass().getResource("files/icon.png")).getImage();" make my Program invisible?

这是我写的

 Image icon = new ImageIcon(getClass().getResource("files/icon.png")).getImage();

在 JFrame 中扩展 class 然后用

设置框架的图标
this.setIconImage(icon);

我是这样做的,而不是简单地使用路径,否则如果我将项目导出为可执行文件 .jar,图标就会消失。 (如此处所示:Once exported, java cannot find/draw images

现在出现的问题是,可执行文件 .jar 按其应有的方式工作(它创建一个文件夹,以及一个 .xml 文件并写入其中),但没有生成可见框架。 但是,如果我 运行 eclipse 中的程序,一切正常并且我看到了框架。 我发现,问题必须出在 ImageIcon 的创建上,因为如果我 运行

getClass().getResource("files/icon.png");

一切正常。 文件也在原处,所以这应该不是错误。

希望你能帮助我并提前致谢。

好吧伙计们,都是我的错... @JBNizet 你又找到了正确的线索......这是路径 "files/icon.png" -> "Files/icon.png"

的情况