0
我的项目在eclipse中运行得很好,但是导出为可执行jar会导致一堆问题。 .jar不可执行,doubleclicking什么也不做。在cmd中的.jar上运行java -jar会给出很多NPE,显然当从.jar运行时扫描器为null。 getResource返回null,我不知道为什么。Eclipse导出为可执行jar NullPointerException
Scanner in = null;
try {
in = new Scanner(new FileReader(getClass().getResource(filename)
.getFile()));
readLine(in);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
凡filename = "../001.txt"
运行扫描仪类是在game/
。文件001.txt
是levels/
所以../001.txt
应该工作。
这是明显的样子将.jar
Manifest-Version: 1.0
Class-Path: .
Main-Class: game.Game
这是一个非常恼人的问题,并为谷歌搜索提供无解小时里面,我也有类似的问题之前,但那是与实际加载相对路径而不是NPE。
这工作,谢谢! – arynaq 2013-04-08 12:57:52