-1

This is the code:

private static Point c;
//c.set(1,1); -> error: "cannot resolve symbol set"??
.
.
.

    @Override
        public boolean onTouchEvent(MotionEvent event){
            switch (event.getAction()){
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_MOVE:
                    c.set((int)event.getX(),(int)event.getY());
            }
            return true;
        }

When I touch anywhere on the screen the app crashes and I get the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Point.set(int, int)' on a null object reference
Zoe
  • 27,060
  • 21
  • 118
  • 148
tacofisher
  • 167
  • 4

1 Answers1

0

The Point c is null because you haven't initialized it. And to initialize it you should write

c = new Point(); // before setting coordinates to c

which makes a new object of the class Point.

Niraj Niroula
  • 2,376
  • 1
  • 17
  • 36