小编典典

加载属性文件时出现Java NullPointerException

java

public class SupplierCalculatorApplet extends JApplet{
...
public void init(){
    loadProperties();
    ...
}

...

private void loadProperties() {
    language = "en-us";//getParameter("Language");
    prop = new Properties();
            try {
                URL urlToProps = this.getClass().getResource("config/" + language + ".properties");
                prop.load(urlToProps.openStream());//Exception Caught Here
            } catch (IOException e) {
            }   
}

在上面指出的行中发现异常。无论语言是否是有效的属性文件,我都会在同一行上捕获相同的异常。


阅读 212

收藏
2020-11-19

共1个答案

小编典典

改成:

prop.load(this.getClass().getResourceAsStream("/config/" + language + ".properties"));
2020-11-19