I am using config.properties file in order to set port. After running I am facing an error:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: 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
HttpServer.setPort(HttpServer.java:83) at
HttpServer.(HttpServer.java:26)
The main class:
public class HttpServer {
static final boolean SSL = System.getProperty("ssl") != null;
static final int PORT = Integer.parseInt(System.getProperty("port", SSL ? "8443" : setPort()));
public static void main(String[] args) {
HttpServer httpServer = new HttpServer();
httpServer.start();
}
public void start(){}
public static String setPort() {
String port = "";
Properties properties = new Properties();
try {
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("src/main/config.properties"));
port = properties.getProperty("server.port");
} catch (IOException e) {
e.printStackTrace();
}
return port;
}
}
I am not able to understand what is the error...