I am trying to read the names of some xml files from a folder located at src > Truss > xml
. The main class is in the Truss
directory. It reads the files fine when the program is run from eclipse however throws this error when exported to a jar and run: (this error is copied from cmd, not eclipse console)
java.lang.NullPointerException
at java.io.FilterInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Truss.main.initiate(main.java:167)
at Truss.main.<init>(main.java:729)
at Truss.main.main(main.java:110)
Here is the code:
try {
InputStream in = main.class.getResourceAsStream("xml");
BufferedReader input = new BufferedReader(new InputStreamReader(in));
String profileName;
while((profileName = input.readLine()) != null) {
loadProfile(profileName.substring(0, profileName.length() - 4));
}
} catch (Exception e) {
e.printStackTrace();
}
The constructor for the while loop is line 167.