Gibt es eine Möglichkeit 2 Klassen miteinander so zu verbinden, das man von beiden aus auf die jeweils andere zugreifen kann (am besten ohne static).
Danke für alle Antworten
Danke für alle Antworten
public class A{
public static void main(String args[]){
B.y();
}
}
Exception in thread "main" java.lang.NullPointerException
public class Main {
public static Map map = new Map(0, 0);
public static GermanTank germanTankForMap = new GermanTank(map);
public static List<GermanTank> germanTank = new LinkedList<GermanTank>();
public static Interface Interface = new Interface(0, 0, map);
public static Selection selection = new Selection();
public static Frame Frame = new Frame(selection, Interface, map, germanTank);
public class GermanTank {
public int x;
public int y;
public int referenceX;
public int referenceY;
public boolean b;
public List<GermanTank> germanTank;
public Map map;
public GermanTank(Map map) {
this.map = map;
}
public GermanTank(int x, int y, boolean b, List<GermanTank> germanTank) {
this.x = x;
this.y = y;
this.b = b;
this.referenceX = x;
this.referenceY = y;
this.germanTank = germanTank;
}
public void update() {
x = referenceX + map.x;
y = referenceY + map.y;
System.out.println(map.getZoom());
}
public class Map {
public static int x;
public static int y;
public int mousex;
public int mousey;
public boolean zoomed = false;
Exception in thread "main" java.lang.NullPointerException
Erstens ich will NICHT das ich statisches verwende.
Zweitens
Java:public class Main { public static Map map = new Map(0, 0); public static GermanTank germanTankForMap = new GermanTank(map); public static List<GermanTank> germanTank = new LinkedList<GermanTank>(); public static Interface Interface = new Interface(0, 0, map); public static Selection selection = new Selection(); public static Frame Frame = new Frame(selection, Interface, map, germanTank);
Java:public void update() { x = referenceX + map.x; y = referenceY + map.y; System.out.println(map.getZoom()); }
Java:public class Map { public static int x; public static int y; public int mousex; public int mousey; public boolean zoomed = false;
In der class Map sind x und y als static deklariert, ich will aber erreichen, dass ich dies ohne static schaffe. Bei System.out.prin.... in der class GermanTank kommt nun der Fehler
Aber wie beheb ich das ohne den boolean zoomed als static zu deklarieren?Java:Exception in thread "main" java.lang.NullPointerException
public int x;
public int y;
public int referenceX;
public int referenceY;
public boolean b;
public List<GermanTank> germanTank;
public Map map = new Map();
Wenn du
meinst, wird aber ein zweites Objekt erstellt, das ich aber nicht brauche, da ich das Object aus der Main class haben will.Java:public int x; public int y; public int referenceX; public int referenceY; public boolean b; public List<GermanTank> germanTank; public Map map = new Map();