So I'm doing some map pathfinding and I keep getting an error
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
However I don't understand how it could be out of bounds. The map is 10,10 therefore the x&y array parts go 0-9.
This is my code
public boolean[][] passable;
public int[][] passCost;
String[][] twoDMap = {
{ ".", ".", ".", ".", ".", "X", ".", ".", ".", "." },// ROW0
{ ".", "X", "X", "X", ".", "X", "X", "X", ".", "." },// ROW1
{ ".", "X", ".", "X", ".", "X", ".", "X", "X", "X" },// ROW2
{ ".", ".", ".", ".", ".", ".", "X", ".", "X", "." },// ROW3
{ ".", "X", "X", "X", "X", "X", "X", "X", ".", "X" },// ROW4
{ ".", ".", ".", ".", ".", ".", ".", ".", "X", "X" },// ROW5
{ "X", "X", ".", ".", ".", ".", "X", "X", ".", "." },// RO6
{ ".", ".", ".", ".", "X", "X", "X", ".", ".", "." },// RO7
{ ".", "X", "X", "X", "X", ".", ".", ".", ".", "." },// ROW8
{ ".", ".", ".", ".", ".", ".", "X", ".", ".", "." } };// ROW9
private void createMap() {
passable = new boolean[twoDMap.length][twoDMap[0].length];
passCost = new int[passable.length][passable[0].length];
System.out.println(twoDMap.length);
System.out.println(twoDMap[0].length);
for (int x = 0; x < passable.length; x++) {
for (int y = 0; y < passable[x].length; y++) {
passCost[x][y] = 1;
System.out.print(twoDMap[x][y]);
passable[x][y] = twoDMap[y][x].charAt(x) == 'X' ? false
: true;
}
System.out.println();
}
}
The error apperas when it gets to the first line in the map, the part where it checks if the selected section contains "X". If it does the problem appears.