2012-07-11 128 views
2

下面的代碼運行良好的getClass()。getResource()方法返回null部署

ThumbnailLabel lblImg =new ThumbnailLabel(new javax.swing.ImageIcon(
    getClass().getResource("/jewelleryerpapplication/GUI/resources/NoPicture.png"))); 

然後我清理在不同崗位提到這個issue.After構建解決方案當我從dist文件夾中雙擊App.jar時,發生以下異常。

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException 
    at javax.swing.ImageIcon.<init>(ImageIcon.java:138) 
+0

試圖通過類加載器,this.getClass()。getClassLoader()。getResource()方法,並確保你有「一致」的對象(例如不在構造函數中) – BigMike 2012-07-11 07:29:00

+0

@BigMike我試過你的解決方案,但結果是一樣的。 – 2012-07-11 07:37:56

+1

發表你的jar文件的jar tvf請 – BigMike 2012-07-11 08:15:08

回答

0

驗證部署JAR實際上幷包含圖像:-)

+0

是的,它包含具有相同路徑的圖像。也驗證了路徑。 – 2012-07-11 07:23:33

相關問題