고정! 모두에게 감사드립니다!Arraylist에서 문자열 분할 (자바)
좋아, 나는 이것이 내게는, ArrayIndexOutOfBoundsException을주는 이유를 모르겠습니다 ..
알과 같은 값을 유지 ArrayList에있다 : 나는 각각의 ArrayList를 얻기 위해 노력하고
다음2,6,m
1,7,w
5,3,c
0,4,w
1,6,w
2,3,w
1,5,w
인을 색인, 행열, 열, 글자로 나눕니다. 임시 직원 [2]이 (가) outofbounds입니다. 왜? 나는 split 메소드가 3 부분, 0, 1, 2를 만들어야한다는 것을 의미합니다. 그래서 2가 나에게 맞는 이유는 무엇입니까. 나는 몇 가지 테스트를 실시했고, 또한 temp [0] 및 temp [1] 호출에 대한 outofbound를 제공했습니다.
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 []을 사용하고 있습니까? 감사합니다, 편집
오스틴은 :은 그냥이 ArrayList의에 루프, 모든 값이 있습니다 달렸다.
boardTiles [x] [x]는 JButton의 2 차원 배열입니다.
예외 인덱스 발생하는 경우 : .length이 표시되어 1
는도 1이다.
'boardTiles'의 정의를 보여주세요. –
어떤 색인에서 예외가 발생합니까? –
입력 한 내용이 항상 위에서 입력 한 입력과 같을 것으로 확신합니까? 매번 입력을 인쇄하여 오류를 제공하는 입력을 확인하십시오. – Danny