2012-04-13 13 views
1

固定!みんな、ありがとう!Arraylistからの分割文字列(java)

わかりましたので、私はこれは私には、ArrayIndexOutOfBoundsExceptionを与えている理由はわからない。..

アルのような値を保持するのArrayListです:私は、それぞれのArrayListを取得しようとしています

ここ
2,6,m 
1,7,w 
5,3,c 
0,4,w 
1,6,w 
2,3,w 
1,5,w 

ですがインデックス、それを分割する:行、列、文字。 temp [2]はoutofboundsです。どうして?私はスプリット方法が3つの部分、0,1、そして2を作るべきであることを意味します。それで2が私にフィットを与えるのはなぜですか?私はいくつかのテストを実行し、それはまた、temp [0]とtemp [1]コールのoutofboundsを与えました。

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); 
     } 
    } 

私はsplitメソッドでString []を使用していますか? おかげで、

-Austin EDITS:

私はすべての値があり、ArrayListの上のループのために走りました。

boardTiles [x] [x]はJButtonの2次元配列です。

例外がインデックスで発生している:1。

.LENGTHが表示されても1です。

+1

「boardTiles」の定義を表示してください –

+0

どのようなインデックスで例外が発生していますか? –

+1

入力は常に上記の入力例のようなものですか?入力を毎回印刷して、どの入力がエラーを出しているかを確認してください。 – Danny

答えて

2

boardTilesは、おそらく入力配列に定義されている値のサイズがありません。

+0

@jeurgendはできません。私はこの部分を実行する前にJFrameでうまく表示されるボードビルダーメソッドを実行します。だからそれは問題ではない。 – Austin

0

al.get(i)の出力を行い、それが本当にコンマで区切られた値の文字列であることを再確認します。