我正在开发一个游戏程序,该程序从文本文件中读取格式化数据,然后分析某个统计数据在给定项目上滚动的概率。问题根源的特定方法,相应地通过文本文件接收两个用户输入和过滤器。
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;
}
我收到的错误消息是:
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)
其中Driver.java:34是我初始化BufferedReader
对象的行。调试程序时,不会执行此行,因此我无法看到它是由while循环中的其余代码引起的问题(尽管该代码可能会导致其他问题,我只是避难所&#39 ; t得到足够的告诉)。我已经尝试过查看类似错误消息的其他解决方案,但没有一个能够解决我的问题。欢迎任何帮助,谢谢。