OnTouchListener,代码跳转,方法不运行

时间:2014-10-28 09:06:01

标签: android listener logcat ontouchlistener ontouch

我有一个简单的代码,只是我不明白为什么我的方法 calculaCoordenadasImagen(MotionEvent e)不起作用

在此监听器中查看日志,了解哪些有效,哪些不用

首先调用该方法的Listener

View.OnTouchListener clickPinta = new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.i("clickPinta","onTouch");
        if(event.getAction()==MotionEvent.ACTION_UP){
            Log.i("ClickPint","ACTION_UP");//this log works
            calculaCoordenadasImagen(event);//this method is not executed
            Log.i("onToucn" ,"pasa calculaCoord");//this log works
            guardaCoordenadas(lastTouchX,lastTouchY);
            return true;
        }
        return false;
    }
};

//这是没有运行的方法,我无法理解为什么。

void calculaCoordenadasImagen(MotionEvent e){
    Log.i("calculaCoordenadas","");//this log dont works
    float []m = new float[9];
    matrix.getValues(m);
    float transX = m[Matrix.MTRANS_X] * -1;
    float transY = m[Matrix.MTRANS_Y] * -1;
    float scaleX = m[Matrix.MSCALE_X];
    float scaleY = m[Matrix.MSCALE_Y];
    lastTouchX = (int) ((e.getX() + transX) / scaleX);
    lastTouchY = (int) ((e.getY() + transY) / scaleY);
    lastTouchX = Math.abs(lastTouchX);
    lastTouchY = Math.abs(lastTouchY);
}

这是有错误的方法,但因为之前的方法没有运行:

void guardaCoordenadas(int x, int y){
    Log.i("guardaCoordenadas","");
    Marking m = new Marking(x,y);
    listaPtos.add(m);
    Log.i("listaPtos0",""+m.x+"-"+m.y);
}

并且有关于logCat-error的第一行:

10-28 09:57:45.683: I/clickPinta(28066): onTouch
10-28 09:57:45.688: I/clickPinta(28066): onTouch
10-28 09:57:45.688: I/ClickPint(28066): ACTION_UP
10-28 09:57:45.688: I/onToucn(28066): pasa calculaCoord
10-28 09:57:45.688: E/InputEventReceiver(28066): Exception dispatching input event.
10-28 09:57:45.693: E/MessageQueue-JNI(28066): Exception in MessageQueue callback: handleReceiveCallback
10-28 09:57:45.713: E/MessageQueue-JNI(28066): java.lang.NullPointerException
10-28 09:57:45.713: E/MessageQueue-JNI(28066):  at com.andres.sun4all.Imagen.guardaCoordenadas(Imagen.java:291)
10-28 09:57:45.713: E/MessageQueue-JNI(28066):  at com.andres.sun4all.Imagen$2.onTouch(Imagen.java:165)
10-28 09:57:45.713: E/MessageQueue-JNI(28066):  at android.view.View.dispatchTouchEvent(View.java:7332)
10-28 09:57:45.713: E/MessageQueue-JNI(28066):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
10-28 09:57:45.713: E/MessageQueue-JNI(28066):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2159)
10-28 09:57:45.713: E/MessageQueue-JNI(28066):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)

我猜问题很愚蠢,但好吧,我找不到它

感谢您的帮助和时间

0 个答案:

没有答案