0

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.

asked Apr 8, 2012 at 3:09

1 Answer 1

1

How about something like:

if ( ( (x+a) >= tiles.length ) || ( (y+b) >= tiles[x+a].length ) )

as your test?

answered Apr 8, 2012 at 3:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.