0

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

检查此侦听器中的日志以了解哪些有效,哪些无效

首先是调用该方法的监听器

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 错误的第一行:

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)

我想这个问题很愚蠢,但是,我找不到它

感谢您的帮助和时间

4

0 回答 0