title: Null Pointer Exception onTouchEvent
body: <p>I have a Null pointer Exception on my class onTouchEvent.
  This is for a Game called Isola, we need to select a Rect (I check wich rect it is with the makeMove() function.)</p>
  
  <pre><code>@Override
  public boolean onTouchEvent(MotionEvent event) {
      // determine if we are in single touch or multi touch mode
  
      if (event.getPointerCount() == 1) {
          // for all events take a copy of the data. on the down press
  
              if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
  
  -&gt; 190      touches[0] = true;
              touchx[0] = event.getX();
              touchy[0] = event.getY();
              makeMove();
  
  
          } else if (event.getActionMasked() == MotionEvent.ACTION_UP) {
              touches[0] = false;
          } 
          }
  
          // we need to invalidate the display and return true to indicate
          // that we
          // have handled the event and we need an update
          invalidate();
          return true;
      }
      // we have not handled the event so use the standard event handling
  
  
  
      return super.onTouchEvent(event);
      }
  </code></pre>
  
  <p>I kon what is a Null pointer Exception, but in this case,I don't understand where it comes from, here is the LogCat : </p>
  
  <pre><code>    03-20 20:37:53.002: E/InputEventReceiver(27540): Exception dispatching input event.
  03-20 20:37:53.002: E/MessageQueue-JNI(27540): Exception in MessageQueue callback: handleReceiveCallback
  03-20 20:37:53.012: E/MessageQueue-JNI(27540): java.lang.NullPointerException
  03-20 20:37:53.012: E/MessageQueue-JNI(27540):  at com.example.loup_theron_2866207.Isola.onTouchEvent(Isola.java:190)
  03-20 20:37:53.012: E/MessageQueue-JNI(27540):  at android.view.View.dispatchTouchEvent(View.java:7706)
  03-20 20:37:53.012: E/MessageQueue-JNI(27540):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  </code></pre>
  
  <p>The makeMove method :</p>
  
  <pre><code>public void makeMove(){
      try{
      for(int j=0;j&lt;7;j++){
          for(int i=0;i&lt;7;i++){
              if(touchx[0] &lt; tableR[j][i] &amp;&amp; touchx[0] &gt; tableL[j][i] &amp;&amp; touchy[0] &lt; tableB[j][i] &amp;&amp; touchy[0] &gt; tableT[j][i]){
                  if(tableCheck[j][i] == true){
                      return;
                  }
                  else if(tableCheck[j][i] == false){
                      tableCheck[j][i] = true;
  
                  }
              }
          }
      }
      }
      catch(Exception e){
          System.out.println("Null pointer 3");
      }
  }
  </code></pre>
  
  <p>Call of the init() : </p>
  
  <pre><code>// default constructor for the class
  public Isola(Context context) {
      super(context);
      // call the shared init method
      init();
  }
  
  // alternative constructor for the class that takes in two arguments
  public Isola(Context context, AttributeSet attr) {
      super(context, attr);
      // call the shared init method
      init();
  }
  
  // alternative constructor for the class that takes in three arguments
  public Isola(Context context, AttributeSet attr, int defStyle) {
      super(context, attr, defStyle);
      // call the shared init method
      init();
  }
  </code></pre>
  
  <p>The init : </p>
  
  <pre><code>private void init() {
      // create a few paint objects for drawing up to three different colours
      // for our squares
  try {
      btn_bottom.setOnClickListener(this);
      red = new Paint(Paint.ANTI_ALIAS_FLAG);
      green = new Paint(Paint.ANTI_ALIAS_FLAG);
      black = new Paint(Paint.ANTI_ALIAS_FLAG);
      white = new Paint(Paint.ANTI_ALIAS_FLAG);
      red.setColor(0xFFFF0000);
      green.setColor(0xFF00FF00);
      black.setColor(0x00000000);
      white.setColor(0xFFFFFFFF);
      white.setStyle(Paint.Style.FILL_AND_STROKE);
  
      // initialise all the touch arrays to have just 3 elements as we will
      // only try three
      // touch for now
      touches = new boolean[16];
      touchx = new float[16];
      touchy = new float[16];
      /*
      for(int j=0;j&lt;7;j++){
          for(int i=0;i&lt;7;i++){
              tableL[j][i] = 0;
              tableT[j][i] = 0;
              tableR[j][i] = 0;
              tableB[j][i] = 0;
              tableCheck[j][i] = false;
  
              }
          }
      */
      // initialise a single square that will be shown at all times
      //touchx[0] = 200;
      //touchy[0] = 200;
      // initialise the rectangle
      //squareSelect = new Rect();
      //squareSelect = new Rect(-75, -75, 75, 75);
  
      square.setStrokeWidth(3);
      square.setStyle(Paint.Style.STROKE);
      square.setColor(Color.BLACK);
  
      squareC.setStrokeWidth(3);
      squareC.setStyle(Paint.Style.FILL);
      squareC.setColor(Color.BLACK);
  }
  catch(Exception e){
  System.out.println("Null pointer 2" + e);
  }
  }
  </code></pre>
  
  <p>Thank you !</p>