Exception in thread “main” java.lang.ExceptionInInitializerError Causés par: java.lang.NullPointerException

Je suis à l'aide de config.fichier de propriétés pour configurer le port. Après l'exécution, je suis confronté à une erreur:

Exception in thread "main" java.lang.ExceptionInInitializerError

Causés par: java.lang.NullPointerException à

java.util.Propriétés$LineReader.readLine(Propriétés.java:434) à

java.util.Les propriétés.load0(Propriétés.java:353) à

java.util.Les propriétés.charge(Propriétés.java:341) à

HttpServer.setPort(HttpServer.java:83) à

HttpServer.(HttpServer.java:26)

La classe principale:

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;
    }
}

Je ne suis pas en mesure de comprendre ce qu'est l'erreur...

  • Que pensez-vous getResourceAsStream("src/main/config.properties") fait et pourquoi pensez-vous ainsi?
  • veuillez vous référer à cette réponse sur la façon de lire les propriétés de fichier, stackoverflow.com/questions/333363/...
InformationsquelleAutor jbakirov | 2015-05-30