【发布时间】:2014-12-31 06:21:49
【问题描述】:
我的代码有点问题,它总是抛出 NullPointerException:
public class WhateverResource extends ServerResource {
@Get("json")
public Representation represent(){
InputStream is = getContext().getClass().getClassLoader().getResourceAsStream("/whatever.properties");
Properties props = new Properties();
try {
props.load(is); // NPE here!
String whatever = props.getProperty("whatever_key");
setStatus(Status.SUCCESS_OK);
} catch (IOException e) {
e.printStackTrace();
setStatus(Status.SERVER_ERROR_INTERNAL);
}
return new StringRepresentation(props.toString());
}
}
我检查了生成的 WAR 文件,在目标文件夹中,WEB-INF 文件夹下有 properties 文件。这段代码有什么问题?
【问题讨论】:
标签: java google-app-engine restlet