난 무작위 값으로 배열 레스토랑을 채우고 싶다. 내가 어떻게 그럴 수 있니? 빈 때 나를 nullpointerexception 예외를 줘. 나는 이미 배열을하려고 노력했다. 그것 doenst 일을 넣어. 또는 예외클래스 배열을 채우는 방법? 나는 배열 outofboundsexception을 해결하기 위해 이것을 필요로한다
private Restaurante[] restaurante= new Restaurante[100];
for (int i = 0; i < lines.length; i++) {
String[] row = lines[i].toString().split("-");
identificador[i] = Integer.parseInt(row[0]);
restaurante[i].setNome(row[1]);
restaurante[i].setLugares(Integer.parseInt(row[2]));
restaurante[i].setLocalidade(row[3]);
restaurante[i].setTipoDeComida(row[4]);
if (identificador[i] == this.id) {
linhasescritas[contador]=i;
contador++;
model.addRow(row);
}
}
예외에 대한 해결책은 광고 식당 [I] .setNome (행 [1])에
예외 스레드에서 "AWT-EventQueue의-0"java.lang.NullPointerException이
배열이 비어 있기 때문에 ArrayIndexOutOfBoundException을 얻지 못합니다. 범위를 벗어난 (즉, 음수 또는> = 배열의 길이) 색인에 액세스하므로 가져옵니다. 배열'lines'이 배열'Restaurante'보다 길기 때문에'IndexOutOfBoundsException'을 얻을 수 있습니다. 예외는 아마도 다음과 같을 것입니다. java.lang.ArrayIndexOutOfBounds : 100' – Turing85
As @ Turing85. 실제 예외를 게시 한 경우 도움이 될 수있는 사람이 누구에게 어떤 행이 표시되는지 알 수 있도록 도움이 될 수 있습니다. 'i'가> = 100이되거나 줄 중 하나에 "-"가 없습니다. – theFunkyEngineer
나는 예외가 nullpointer의 wrog이었다. 죄송합니다 –