NullPointerException... wo?
[geloest]
Hi, ich habe eine NullPointerException, finde aber keine Ursache.
Hier der code:
(>>>: Diese Zeilen werden als Fehler genannt)

Hi, ich habe eine NullPointerException, finde aber keine Ursache.
Hier der code:
(>>>: Diese Zeilen werden als Fehler genannt)
Code:
public class Karte {
public KartenFeld[][] karte;
public static void main(String[] args){
>>> Karte welt = new Karte();
welt.printKarte();
}
public Karte() {
>>> this.karte[0][0]= new Wiese();
this.karte[1][0]= new Wiese();
this.karte[2][0]= new Wiese();
this.karte[0][1]= new Wiese();
this.karte[1][1]= new Mauer();
this.karte[2][1]= new Mauer();
this.karte[0][2]= new Wiese();
this.karte[1][2]= new Wiese();
this.karte[2][2]= new Wiese();
}
public void printKarte(){
for(int y=0; y<this.karte.length; y++){
for(int x=0; x<this.karte[y].length; x++){
System.out.print(this.karte[y][x].typ+"x");
}
System.out.println();
}
}
}
Code:
public abstract class KartenFeld {
String typ;
boolean walkable;
}
Code:
public class Wiese extends KartenFeld {
public Wiese(){
this.typ = "O";
this.walkable = true;
}
}
Code:
public class Mauer extends KartenFeld {
String typ = "X";
boolean walkable = false;
}
Zuletzt bearbeitet: