所以我有一個在Eclipse中完美運行的項目,但是當我將它導出爲runnable .jar時,我的.png資源文件的路徑不會因爲src文件夾不包含在導出的.jar文件中。src文件夾不包含在導出.jar中搞亂了資源路徑(Eclipse)
createTexture("resources/grass.png", 0);
這是我使用路徑的地方。
public static void createTexture(String path, int index){
try (InputStream inputStream = Drawer.class.getClassLoader().getResourceAsStream(path)){
textureDecoder = new PNGDecoder(inputStream); [...]
現在我得到的錯誤
Exception in thread "main" java.lang.NullPointerException
at de.matthiasmann.twl.utils.PNGDecoder.readFully(PNGDecoder.java:802)
at de.matthiasmann.twl.utils.PNGDecoder.<init>(PNGDecoder.java:112)
at workers.Drawer.createTexture(Drawer.java:80)
at workers.Drawer.openglSetup(Drawer.java:44)
at jonta.Main.setUp(Main.java:41)
at jonta.Main.main(Main.java:121)
OLD: 這顯然是我的錯誤,當我嘗試運行.jar:
java.io.FileNotFoundException: src\resources\grass.png
我當然包括更多的代碼/配置,如果這將是相關的。
編輯:問題解決了,謝謝!
jar中的對象不是文件,無法使用File API進行訪問。 –