문제

I am making an application, it seems to work run very well, but the application has some kind of a bug. Every time i am touching the view and moving my finger outside the view and releasing, it crashes.

Here is an explanation of my problem:![enter image description here][1]

Here is some of my code that might be the problem:

public class Game extends View implements OnTurnBasedMatchUpdateReceivedListener  {

public Game(GameActivity activity){
    super(activity);
    this.mGameActivity = activity;
    this.mGameBoard    = new GameBoard(activity);
    this.setFocusable(true);
    this.setFocusableInTouchMode(true);
    this.setClickable(true);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    // TODO Subtract movementpoints
    int eventCode = event.getAction();
    switch(eventCode){
    case MotionEvent.ACTION_DOWN:
        return true;
    case MotionEvent.ACTION_MOVE:
        return true;
    case MotionEvent.ACTION_UP:
        return true;
    default:
        return true;            
    }
}

Here is the error log:

04-08 23:00:47.585: E/InputEventReceiver(18313): Exception dispatching input event.
04-08 23:00:47.585: E/MessageQueue-JNI(18313): Exception in MessageQueue callback: handleReceiveCallback
04-08 23:00:47.620: E/MessageQueue-JNI(18313): java.lang.NullPointerException
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at com.boentertainment.quizgame.Game.onTouchEvent(Game.java:199)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.View.dispatchTouchEvent(View.java:7713)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
04-08 23:00:47.620: E/MessageQueue-JNI(18313):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
도움이 되었습니까?

해결책

You'll need to learn to debug your application. Then you can do the things that cause the bug, and see the values of your variables at that time. Another usefull thing is the logging system. You can find more information here if you're using Eclipse: How to Debug Android application line by line using Eclipse?

Your switch definitely needs break-statements if you are going to implement code for each case in the future:

switch(eventCode){
case MotionEvent.ACTION_DOWN:
    return true;
    break;
case MotionEvent.ACTION_MOVE:
    return true;
    break;
case MotionEvent.ACTION_UP:
    return true;
    break;
default:
    return true;            
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top