Why do certain numbers throw ArrayIndexOutOfBoundsException?
I have a very quick question: why do certain numbers throw an
ArrayIndexOutOfBoundsException 1? I'm not sure if this is a problem with
Java or my code.
If I have a string that looks something like this:
10:64
This will work fine when parsing those two integers.
String string = "10:64";
String[] split = string.split(":");
int first = 0;
int second = 0;
try {
first = Integer.parseInt(split[0]);
second = Integer.parseInt(split[1]);
} catch (NumberFormatException a) {
a.printStackTrace();
}
But it seems like if the integer 'second' is (I've tried only a couple
numbers) is something like 10, it throws the exception.. why?
Edit: Here is a part of my code:
for (String str : getConfig().getStringList("itemstack")) {
String[] split = str.split(":");
Item item = null;
int size = 0;
try {
item = Item.byId[Integer.parseInt(split[0])];
} catch (NumberFormatException a) {
a.printStackTrace();
return;
}
try {
size = Integer.parseInt(split[1]);
} catch (NumberFormatException b) {
b.printStackTrace();
return;
}
}
The error is referring to the line:
size = Integer.parseInt(split[1]);
Edit 2: and here is what I have in the yaml file:
itemstack:
- 282:10
No comments:
Post a Comment