0
Ich habe versucht, zweidimensionale ArrayList
i NullPointerException
in 7 Zeile erhalten erstellenNullpointer in Arraylist java
ArrayList<Integer>[] g = new ArrayList[500];
for(int i = 1;i < HEIGHT - 1; i++){
for(int j = 1;j < WIDTH - 1; j++){
if(MAP[i][j] == 0){
int cur = i * HEIGHT + j;
if(MAP[i+1][j] == 0){
g[cur].add(cur + HEIGHT);
}
if(MAP[i-1][j] == 0){
g[cur].add(cur - HEIGHT);
}
if(MAP[i][j+1] == 0){
g[cur].add(cur + 1);
}
if(MAP[i][j-1] == 0){
g[cur].add(cur - 1);
}
}
}
}
, die mit 500 null poin ein leeres Array ist Ters, die auf Array-Listen verweisen könnten, aber Sie müssen jedem der 500 zuerst (in einer For-Schleife, vermutlich) Arraylists zuweisen –
Mögliches Duplikat von [Was ist eine NullPointerException, und wie behebe ich es?] (http: //stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) –