我使用NetBeans GUI生成器有它運行良好,但是當我複製從NetBeans中的源代碼,並在Eclipse中粘貼了一個程序我收到以下錯誤。異常在Java異常在線程「AWT-EventQueue的-0」顯示java.lang.NullPointerException
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at frame2.initComponents(frame2.java:100)
at frame2.<init>(frame2.java:17)
at frame2$5.run(frame2.java:671)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
我在網上搜索它,發現我可能沒有初始化導致這個異常的東西。因此,這裏的問題: -
1)如果有,爲什麼程序在Netbeans中運行良好任何異常?
2)我怎麼能讓這段代碼在Eclipse上運行?
這裏是我的代碼的鏈接:
而且我的推杆上的正確位置的圖像。
這個錯誤表明你在'frame2.java'第100行中做了錯誤的事情,你可能會將'null'傳遞給'ImageIcon'構造函數。 – zapl