我目前正在使用JFrama構建一個小型Java遊戲。我有一些外星人跌倒,他們都是圖像,他們正確加載。現在我想爲球員提供圖像,但是當我這樣做時,我的整個項目都被燒燬了。我得到這樣在JFrame Java應用程序中找不到資源
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gamepackage.Game.draw(Game.java:50)
at gamepackage.Game.paint(Game.java:45)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1100(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(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$1.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)
例外,我試圖找出問題的所在,我這裏就結束了 ImageIcon ii = new ImageIcon(this.getClass().getResource(player));
和player
是private String player = "../img/player_64.png";
爲外星人圖像中的加載相同的方式和兩個圖片是在同一個方向。所以我嘗試了很多東西,但目前爲止還沒有成功。
用於加載圖像的行應該引發異常;嘗試捕捉它。 –
所以我會抓住上面粘貼的這個。我不想要這個。我想正確地引導圖像,因爲我需要它:/ – Bankin
'「../ img/player_64.png」'這個課程包是什麼?資源相對於班級的位置是什麼?你怎麼能認爲我們可以幫助你解決這個*沒有這些基本信息?我們剛剛從魔法中獲益.. –