2016-04-10 142 views
0

當我嘗試從cmd打開.JAR文件時,爲什麼會出現此錯誤?執行jar文件時出錯

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException 
    at javax.swing.ImageIcon.<init>(Unknown Source) 
    at sqlprojectgestor.Gestor.initComponents(Gestor.java:311) 
    at sqlprojectgestor.Gestor.<init>(Gestor.java:28) 
    at sqlprojectgestor.Gestor.lambda$main$0(Gestor.java:1017) 
    at java.awt.event.InvocationEvent.dispatch(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$500(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.run(Unknown Source) 

我嘗試運行與雙擊.jar文件,但它不會打開...

+0

它看起來像是在你的代碼中發生錯誤。爲了調試它,我們需要看代碼。你可以在沒有問題的情況下從IDE運行代碼嗎? – nhouser9

+0

我認爲錯誤在你的圖像路徑中。嘗試使用相對路徑。 –

+0

如果我從netbeans運行我的程序,運行時沒有錯誤,這就是爲什麼我覺得它很奇怪:/ @ nhouser9 –

回答

0

我懷疑你的問題是由不包括在你的JAR圖像造成的。請看這個問題:如何做到這一點:這可能是因爲你沒有在JAR中包含圖像作爲資源。看到這個問題:Add image to JAR Java