InputStream.getResourceAsStream() giving null pointer exception

后端 未结 6 1394
广开言路
广开言路 2020-12-11 19:08

The line persistenceProperties.load(is); is throwing a nullpointerexception in the following method. How can I resolve this error?

6条回答
  •  眼角桃花
    2020-12-11 20:01

    Two things:

    First, try a path of test/samples/... or /test/samples/...

    Secondly, and much more importantly, don't ever, ever, ever write this:

    try {
        // some stuff
    } catch (IOException ignored) {}
    

    All this says is: do some stuff, and if it goes wrong, then fail silently. That is never the right thing to do: if there's a problem, you want to know about it, rather than madly rushing on as if nothing had happened. Either do some sensible processing in your catch block, or else don't have the try/catch and add a throws IOException to your method signature so it can propagate upwards.

    But at the moment, you're just sweeping things under the carpet.

提交回复
热议问题