K
Kaukassus
Gast
Hallo liebe Community, ich war gerade dabei ein Objekt vom Typ Wald zu erstellen, jedoch meldet der Compiler einen Fehler und ich finde ihn schon die ganze Zeit nicht :S... kann jemand helfen?
Lg
Und noch die Fehlermeldung, damit man auch ohne Kompilieren weiß, worum es geht:
Lg
Java:
import java.io.*;
public class Baum {
protected boolean gefaellt;
public Baum(int x, int y){
}
public String toString(){
if(this.gefaellt==true){
return "x";
}
else return "o";
}
class Wald extends Baum{
Baum[][] wald;
void Matrix(int x,int y){
for(int i=0;i<x;i++){
for(int j=0;j<y;i++){
System.out.println(wald[x][y].toString());
}
}
}
public Wald(int x,int y){
super(x,y);
wald = new Baum[x][y]; //x=anzahl Zeilen, y=anzahl Spalten
Matrix(x,y);
}
public Baum baumfaellen(int zeile, int spalte){
wald[zeile][spalte].gefaellt = true;
wald[zeile][spalte].toString();
return null;
}
}
public static void main(String[] args)throws IOException{
InputStreamReader inStream = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(inStream);
Wald wald1 = new Wald(4,4); //Das funktioniert nicht!!!!!!!!!!
}
}
Und noch die Fehlermeldung, damit man auch ohne Kompilieren weiß, worum es geht:
Code:
Baum.java:50:21: error: non-static variable this cannot be referenced from a static context
Wald wald1 = new Wald(4,4); //Das funktioniert nicht!!!!!!!!!!
^
1 error
Zuletzt bearbeitet von einem Moderator: