我在App.java
的{{1}} my.package
和src/main/java
中的几张图片中有my.package.resources
的日食中有一个maven项目
我看着罐子,结构是这样的:
MyApp
|- chrriis \\ library stuff
|- com \\ stuff with google and sun
|- javax
|- META-INF \\ contains MANIFEST.MF and other maven stuff
|- org \\ contains most of my used libraries
|- my
| |- package
| | | App.class
| | | App$1.class
| | |- resources
| | | |-picture.png
当我加载如下图片时:
JPanel p1 = new JPanel(new GridBagLayout());
p1.add(new JLabel(new ImageIcon(App.class.getResource("resources"+File.separator+"picture.png"))));
并在eclipse中运行它,它工作正常。但是当我将它导出到一个可运行的jar时,它会给我这个错误:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
...
但是当我将picture.png移动到my.package
时就行了
App.class.getResource("picture.png")
它工作正常。
我尝试了这四种解决方案,但它们对我不起作用: (1)(2)(3)(4)
任何帮助都将不胜感激。