Answer the question
In order to leave comments, you need to log in
How to fix NPE error when running program as jar?
This is how I pull the json file from the resources. If you run the program through the studio, then everything starts without errors.
File file = new File(getClass().getResource("questions.json").getFile());
questions = gson.fromJson(new FileReader(file), Question[].class);
Answer the question
In order to leave comments, you need to log in
Use getClass(). getResourceAsStream("questions.json")
You will receive InputStream, and further work with it as it is necessary. So it seems that the absolute path will not be used
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question