I can't really wrap my head around what's going on with my program. Everything works fine before building the jar file. When running the jar file I get Exception in thread "main" java.lang.NullPointerException
The NullPointerException happens when I call System.out.println(FileHandler.readInputStream(path));
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at RaspberryPiServer.FileHandler.FileHandler.readInputStream(FileHandler.java:17)
at RaspberryPiServer.Client.<init>(Client.java:47)
at RaspberryPiServer.Main.main(Main.java:277)
The important parts. Testing the relevant parts:
String path = "Client\\key.txt";
System.out.println(FileHandler.readInputStream(path));
// RaspberryPiServer.FileHandler class:
public static String readInputStream(String path) {
InputStream input = RaspberryPiServer.Utils.ResourceLoader.loader(path);
java.util.Scanner s = new java.util.Scanner(input);
s.useDelimiter("\\A");
String streamString = s.hasNext() ? s.next() : "";
s.close();
return streamString;
}
// RaspberryPiServer.Utils.ResourceLoader class
public static InputStream loader(String path) {
InputStream input = ResourceLoader.class.getResourceAsStream(path);
if (input == null) {
input = ResourceLoader.class.getResourceAsStream("/" + path);
}
return input;
}
I also did jar tf RaspberryPi.jar
to confirm that the key.txt file exists within the jar file.
META-INF/MANIFEST.MF
Client/
Client/key.txt
log4j.properties
Logging.log
META-INF/
RaspberryPiServer/
...
...