I tried using an if statement to see if the index returns null, and skips over if it does, but it still keeps getting an array index out of bounds exception.
...
if(tiles[x+a][y+b] == null){
System.out.println("Would have been an error");
} else if(tiles[x+a][y+b].getType() == type) {
tiles[x+a][y+b].setTile(type);
} else {
System.out.println("Not found");
}
...
Mainly the first two lines are what the question's about. I'm trying to get it so that it goes through the array, but skips over anything that would get an array index out of bounds exception. If you need anymore background info, please let me know. I tried to cut it down as much as I could.
1 Answer 1
How about something like:
if ( ( (x+a) >= tiles.length ) || ( (y+b) >= tiles[x+a].length ) )
as your test?
Explore related questions
See similar questions with these tags.