0

I'm getting an NPE in this method:

public static File getFile(String path){
    File file = null;
    path = ("res/" + path).replace("/", File.separator);
    try {
        file = new File(Main.getInstance().getClass().getResource(path).toURI());
    } catch (URISyntaxException e){
        e.printStackTrace();
    }
    return file;
}

I get the same if I switch to this line:

file = new File(Main.class.getResource(path).toURI());

In both cases, getResource(path) returns null, and so the method call after that fails.

It works fine when I launch it using my IDE but it gives the NPE when I try launching the Jar.

EDIT:

I tried the solutions to the questions linked and none of them work. I looked all over the internet and still no luck.

halfer
  • 19,824
  • 17
  • 99
  • 186
Badr B
  • 998
  • 1
  • 9
  • 17

0 Answers0