【发布时间】:2015-12-17 06:12:04
【问题描述】:
所以我有一个可以在 Eclipse 中完美运行的项目,但是当我将它导出为可运行的 .jar 时,我的 .png 资源文件的路径将不再起作用,因为 src 文件夹不包含在导出的 .jar 中。
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)
旧: 这显然是我尝试运行 .jar 时遇到的错误:
java.io.FileNotFoundException: src\resources\grass.png
如果相关的话,我当然会包含更多我所做的代码/配置。
编辑:问题已解决,谢谢!
【问题讨论】:
-
jar 中的对象不是文件,不能使用 File API 访问。