Code:
public void loadPriceList() {
int itemId = 0;
BufferedReader file = null;
String line = "", token = "", token2 = "", token2_2 = "", token3[] = new String[10];
try {
file = new BufferedReader(new FileReader("../Data/items/itemPrices.cfg"));
line = file.readLine().trim();
} catch (IOException e) {
Misc.println("Error loading price list.");
}
while (line != null) {
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot).trim();
token2 = line.substring(spot + 1).trim();
token2_2 = token2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token3 = token2_2.split("\t");
if (token.equals("item")) {
itemId = Integer.parseInt(token3[0]);
itemList[itemId].minPrice = Integer.parseInt(token3[1]);
itemList[itemId].basicPrice = Integer.parseInt(token3[2]);
itemList[itemId].maxPrice = Integer.parseInt(token3[3]);
}
} else {
if (line.contains("[")) {
try {
file.close();
} catch (Exception exception) {
}
file = null;
}
}
try {
line = file.readLine().trim();
} catch (Exception exception1) {
try {
file.close();
} catch (Exception exception) {
}
file = null;
}
}
}
I get a nullpointer, because the itemId isn't read correctly, anyone knows the solution?
example of the cfg file:
Code:
item = 2 178 187 196
item = 6 123800 130300 136800
item = 8 117000 123200 129300
item = 10 134700 141800 148900
item = 12 132200 139200 146100
item = 36 18 19 20