title: Implementing a bucket-like method in Android
body: <p>I created an application for drawing in Android.
  I want to have a tool similar to Microsoft Paint's bucket tool - the tool will fill the closed area with the chosen color. So on click, I wrote:</p>
  
  <pre><code>boolean[][] didVisit = new boolean[getWidth()][getHeight()];
                  visit ((int)event.getX(), (int)event.getY(), didVisit, mBitmap.getPixel((int)event.getX(), (int)event.getY()));
  </code></pre>
  
  <p>And the visit method is:</p>
  
  <pre><code>private void visit (int x, int y, boolean[][] didVisit, int color)
          {
              if ( x &lt; 0 || x &gt;= didVisit.length || y &lt; 0 || y &gt;= didVisit[0].length  )
              {
                  return;
              }
              if (  mBitmap.getPixel(x,y) != color )
                  return;
              if ( didVisit[x][y] )
                  return;
              didVisit[x][y] = true;
              mBitmap.setPixel(x, y, p.getColor());
              visit(x-1,y,didVisit,color);
              visit(x,y+1,didVisit,color);
              visit(x+1,y,didVisit,color);
              visit(x,y-1,didVisit,color);
          }
  </code></pre>
  
  <p>However, this causes the application to crush (force close). I'm pretty much perplexed. I reviewed it dozens of times, and still could not see what caused the force close.</p>
  
  <p>I would be glad for any kind of help.
  Thanks in advance.</p>