开发者

Nullpointer exception when using setLocation of an object of type Point2D.double

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 nullpoint开发者_运维技巧er 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜