FIXED! Thanks everyone!
Okay, so I am not sure why this is giving me an ArrayIndexOutOfBoundsException..
al is an arraylist holding values such as:
2,6,m
1,7,w
5,3,c
0,4,w
1,6,w
2,3,w
1,5,w
Here is where I am trying to get each arraylist index, split it into: row, col, letter. It is saying that temp[2] is outofbounds. Why? I mean the split method should make 3 parts, 0,1, and 2. So why is 2 giving me fits. I ran some tests and it also gave outofbounds for temp[0] and temp[1] calls.
for (int i = 0; i < al.size(); i++) {
String[] temp = al.get(i).toString().split(",");
System.out.println(temp.length);
System.out.println(temp[1]);
if (temp[2].equals("m")) {
boardTiles[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])].setIcon(mousetile);
boardTiles[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])].putClientProperty("mouse", true);
}
if (temp[2].equals("c")) {
boardTiles[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])].setIcon(cheesetile);
boardTiles[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])].putClientProperty("cheese", true);
}
if (temp[2].equals("w")) {
boardTiles[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])].setIcon(metalwall);
boardTiles[Integer.parseInt(temp[0])][Integer.parseInt(temp[1])].putClientProperty("wall", true);
}
}
Am I utilizing the String[] with the split method wrong or something? Thanks, -Austin
EDITS:
I just ran a for loop on the arraylist, all of the values are there.
boardTiles[x][x] is a 2d array of JButtons.
Exception is occuring at index: 1.
the .length is showing is 1 as well.
boardTilestemp.lengthshow before you get the exception? It looks like one of your strings doesn't have the right format..lengthshould show 3, right? but is showing 1.