I'm trying to set the file path of a resource file in an Eclipse project on Windows, game.json
but when I try to crate an input stream string from the InputStream I get a NullPointerException.
To debug this I've checked the correct file path to my resource is in place, which it seems it is. Also I've set a break point on the error and it seems to be happening at this line:
String inputStreamString = new Scanner(source,"UTF-8").useDelimiter("\\A").next();
Does anyone know why the JSON file isn't being found using the given path?
These are the steps I'm taking to reference the resource's file path, but I'm getting an NPE:
private static final String GAME_FILE = "/game.json";
//I've also tried the path, "resources/game.json" but got the same error..
InputStream source = getClass().getClassLoader().getResourceAsStream(GAME_FILE);
String inputStreamString = new Scanner(source,"UTF-8").useDelimiter("\\A").next();
ObjectMapper mapper = new ObjectMapper();
// read from file, convert it to Location class
Location loc = mapper.readValue(new File(inputStreamString), Location.class);
This is the structure of my project tree:
This the error being thrown:
Exception in thread "main" java.lang.NullPointerException: source
at java.util.Objects.requireNonNull(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at gmit.GameParser.parse(GameParser.java:23)
at gmit.Main.main(Main.java:13)