문제

This is my first time using points and I seem to run into an issue when initially setting the location of a Point2D object. Here is my code snippet:

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);

I get the nullpointer exception when trying to do loc.setLocation(). I've been messing around trying to figure out if I'm initializing the point2s incorrectly and if so how. Could someone help me?

도움이 되었습니까?

해결책

Oh wait it's kinda obvious. You need to make a new Point2D.Double before setting it's location.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top