固定!みんな、ありがとう!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です。
「boardTiles」の定義を表示してください –
どのようなインデックスで例外が発生していますか? –
入力は常に上記の入力例のようなものですか?入力を毎回印刷して、どの入力がエラーを出しているかを確認してください。 – Danny