Function in java does not finish
<p>Greetings,</p>

<p>this is my very first question and I just do programming as a hobby so keep that in mind when trying to help me, please.</p>

<p>I have a function that tries to read the centre point of a crosshair. Something like a position finder in a game. The code looks like this:</p>

<pre><code>public static Point location(BufferedImage image) {
        int pixelLeft;
        int pixelTop;
        Point point = new Point();

        for (int i = Main.RADAR_TOP+1; i &lt; Main.RADAR_BOTTOM; i++) {
            pixelLeft = image.getRGB(Main.RADAR_LEFT+7, i);
            if ((((pixelLeft&gt;&gt;16) &amp; 0xff) &gt; 35 &amp;&amp;
                  ((pixelLeft&gt;&gt;8) &amp; 0xff) &gt; 35 &amp;&amp;
                  ((pixelLeft) &amp; 0xff) &gt; 35)){
                point.y = i;
                break;
            }
        }

        for (int j = Main.RADAR_LEFT+1; j &lt; Main.RADAR_RIGHT; j++) {
            pixelTop = image.getRGB(j, Main.RADAR_TOP+5);
            if ((((pixelTop&gt;&gt;16) &amp; 0xff) &gt; 35 &amp;&amp; 
                  ((pixelTop&gt;&gt;8) &amp; 0xff) &gt; 35 &amp;&amp; 
                  ((pixelTop) &amp; 0xff) &gt; 35)){
                point.x = j;
                break;
            }
        }

        System.out.println("location: "+point.x+","+point.y);
/**        lastX = point.x;
        lastY = point.y;*/
        return point;
    }
</code></pre>

<p>What happens is that at times, this function simply does not return control to the main application. Basically it gets stuck running. Therefore the last comment in the function to do a check. I first thought that maybe it had something to do with reading static members of the class where the function resides so I commented those out as you can see at the end. The problem still occurs though.</p>

<p>I can't really see or think of any reason for this behaviour. I'll appreciate very much any ideas or comments that could point me to a mistake or something.</p>
