1

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.

11
  • 1
    please show definition of boardTiles Commented Apr 13, 2012 at 15:50
  • what Index is the exception happening at? Commented Apr 13, 2012 at 15:50
  • 1
    Are you sure you inputs are always like the example inputs you gave above? Try printing out the input each time to see which input is giving you the error. Commented Apr 13, 2012 at 15:50
  • What does temp.length show before you get the exception? It looks like one of your strings doesn't have the right format. Commented Apr 13, 2012 at 15:50
  • 2
    @Austin: .length should show 3, right? but is showing 1. Commented Apr 13, 2012 at 15:59

2 Answers 2

2

boardTiles probably doesn't have the size of some values defined in your input array.

Sign up to request clarification or add additional context in comments.

1 Comment

@jeurgend can't be, before I do this part it runs a boardbuilder method which displays fine in the JFrame. So that's not the issue.
0

Do a print of al.get(i) and double check that it is indeed a comma separated string of values.

Comments

Your Answer

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.