Dies ist das erste Mal, dass ich Punkte verwende, und es scheint mir ein Problem zu bestehen, wenn ich anfänglich die Position eines Point2D-Objekts festlege. Hier ist mein Code-Schnipsel:Nullpointer-Ausnahme bei Verwendung von setLocation eines Objekts vom Typ Point2D.double
public class Circle {
private Ellipse2D circle;
private int radius,speed=4,direction;
private Color color;
private Point2D.Double loc=null;
private final int MAXSIZE = 15;
public Circle() {
int tempRadius,x,y;
//setting default color
...
//initializing radius
...
//initializing location
x=temp.nextInt(1024); y=temp.nextInt(1024);
loc.setLocation((double)x, (double)y);
Ich erhalte die Nullpointer Ausnahme bei dem Versuch, loc.setLocation() zu tun. Ich habe versucht, herauszufinden, ob ich die Punkte falsch initialisiere und wenn ja, wie. Könnte mir jemand helfen?
Was ist die "Temp" in Ihrem Code? – Pimgd
Und initiierst du jemals loc? – EboMike
Temp ist vom Typ Zufällig. Ich habe vergessen, dass ich diesen Teil blockiert – Jonathan