Thank you for reading this.
What happened was I had a moderately successful battlescape server running on a cheap dedicated server. I decided to copy it to my new computer so I can test updates on there before implementing them into the actual server.
Everything worked fine except now I get this weird ArrayIndexOutOfBounds exception, that I never had while it was running on my server. I didn't modify any of the code in any way, I just moved the files over to a new computer. I kept the same file and directory structure that I had on the server to prevent I/O errors.
I still have a lot to learn about Java so any advice is greatly appreciated.
Here's the stack trace:
Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at ItemHandler.loadItemList(ItemHandler.java:445)
at ItemHandler.<init>(ItemHandler.java:31)
at Server.main(Server.java:51)
Press any key to continue . . .
And here are the methods referenced.
ItemHandler.loadItemList:
Code:
public boolean loadItemList(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
int ReadMode = 0;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./CFG/"+FileName));
} catch(FileNotFoundException fileex) {
misc.println(FileName+": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch(IOException ioexception) {
misc.println(FileName+": error loading file.");
return false;
}
while(EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.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")) {
int[] Bonuses = new int[12]; //line 445 and problem array
for (int i = 0; i < 12; i++) {
if (token3[(6 + i)] != null) {
Bonuses[i] = Integer.parseInt(token3[(6 + i)]);
} else {
break;
}
}
newItemList(Integer.parseInt(token3[0]), token3[1].replaceAll("_", " "), token3[2].replaceAll("_", " "), Double.parseDouble(token3[3]), Double.parseDouble(token3[4]), Double.parseDouble(token3[5]), Bonuses);
}
} else {
if (line.equals("[ENDOFITEMLIST]")) {
try { characterfile.close(); } catch(IOException ioexception) { }
return true;
}
}
try {
line = characterfile.readLine();
} catch(IOException ioexception1) { EndOfFile = true; }
}
try { characterfile.close(); } catch(IOException ioexception) { }
return false;
}
}
ItemHandler.<init>
Code:
public ItemHandler()
{
for (int i = 0; i < MaxGroundItems; i++)
{
GroundItemId[i] = -1;
GroundItemAmt[i] = 0;
GroundItemX[i] = 0;
GroundItemY[i] = 0;
GroundItemTime[i] = 0;
DroppedBy[i] = 0;
heightLvl[i] = 0;
DroppedByName[i] = "";
ItemList[i] = null;
}
loadItemList("item.cfg"); //Line 31
}
Thanks in advance for any help.