I'm working on a program for a game that reads in formatted data from a text file and then analyzes the probability of a certain stat being rolled on a given item. The particular method at the source of the problem, takes in two pieces of user input and filters through the text file accordingly.
public ArrayList<String> analyze(String type, int ilvl){
strImplicits = new ArrayList<>();
// make a new item based on the user input
userItem = new Item(type, ilvl);
try {
// File reading shit
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/src/ImplicitList.txt")));
//File implicitList = new File("ImplicitList.txt");
//Scanner fileReader = new Scanner(implicitList);
String line = "";
String name = "";
String effect = "";
int implicitilvl = 0;
while ((line = reader.readLine()) != null){
if (line.equals("$")) {
line = reader.readLine();
// splitting the line and grabbing data
String[] info = line.split("\t");
name = info[0];
implicitilvl = Integer.parseInt(info[1]);
effect = info[2];
} else if (!line.equals(null) && !line.equals("$")){
String[] tag = line.split(" ");
int weight = Integer.parseInt(tag[1]);
if (userItem.getTags().contains(tag[0]) && weight != 0 && ilvl >= implicitilvl) {
userItem.addRoll(name, effect, weight);
}
} // end else-if
if (line == null)
break;
} // end of while
/**
* Iterate through each line of the text file, looking for the $ delimiter.
* After we find the & character we need to check the mod's tags to see if it applies
*
* if yes, add the weighting to the int variable that represents the pool of mods
* probably would need an arrayList to store and print out the possible variables
*/
} catch (FileNotFoundException e) {
e.getMessage();
} catch (IOException e) {
e.printStackTrace();
}
// string representation of all the possible implicits to be used in combo box
for (Implicit imp: userItem.getPotRolls())
strImplicits.add(imp.toString());
return strImplicits;
}
The error message I receive is:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at Driver.alternative(Driver.java:34)
at VaalUI.handle(VaalUI.java:158)
at VaalUI.handle(VaalUI.java:17)
where Driver.java:34 is the line where I initialize the BufferedReader
object. When debugging the program won't execute past this line so I can't see it being a problem caused by the rest of the code in the while loop (though that code may cause other issues, I just haven't gotten far enough to tell). I've tried looking at other solutions to similar error messages but none of them have worked for my case. Any help welcome, thanks.