Wednesday, 28 August 2013

properties lang.NullPointerException reading from same package

properties lang.NullPointerException reading from same package

I've tried variations on the path to the properties file, but can't seem
to get it correct.
Here's the structure:
src/
„¥„Ÿ„Ÿ properties.properties
„¤„Ÿ„Ÿ teln
„¥„Ÿ„Ÿ ConnectMUD.java
„¥„Ÿ„Ÿ IOUtil.java
„¤„Ÿ„Ÿ PropertiesReader.java
and the error:
run:
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at teln.PropertiesReader.getProps(PropertiesReader.java:16)
at teln.ConnectMUD.main(ConnectMUD.java:18)
and the class in question:
package teln;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PropertiesReader {
private static final Logger LOG =
Logger.getLogger(PropertiesReader.class.getName());
private static Properties props = new Properties();
public static Properties getProps() {
try {
props.load(PropertiesReader.class.getResourceAsStream("/teln/teln.properties"));
} catch (IOException ex) {
Logger.getLogger(PropertiesReader.class.getName()).log(Level.SEVERE,
null, ex);
}
LOG.fine(props.toString());
return props;
}
}
The project is Teln and the package is teln (not good choices, maybe).
see also: http://stackoverflow.com/a/8285636/262852

No comments:

Post a Comment