0

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)
2
  • what is line 199 of Game.java Commented Apr 8, 2014 at 21:47
  • 199? I cant see line 199! Commented Apr 9, 2014 at 8:27

1 Answer 1

0

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;            
}
Sign up to request clarification or add additional context in comments.

3 Comments

break is not needed after return
Thank you for the reply. I'll will debug and see what happens.
I did a debug of my code and found the problem. The problem was a null pointer exception caused by a logic error. Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.