在android studio中获取触摸坐标时出错

时间:2017-10-07 13:44:48

标签: java android

这是代码:

$defaults = [
        'allow_redirects' => RedirectMiddleware::$defaultSettings,
        'http_errors'     => true,
        'decode_content'  => true,
        'verify'          => false,
        'cookies'         => false
    ];

当我触摸屏幕上的任何地方时,应用程序崩溃,我收到以下错误:

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

1 个答案:

答案 0 :(得分:0)

Point c为空,因为您尚未对其进行初始化。要初始化它,你应该写

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

创建类Point的新对象。