my application freezes after entering into the loop
<p>I am developing a code breaking game i.e. Bulls and Cows in android. The problem is that in my main class I have applied a logic to check the numbers. This logic falls under a loop but when i run the application it freezes after entering into the loop. I'm tired of searching the answer on internet. I would be grateful to you people here if you could help out in some way. I regret if my code look lame to you as I'm a beginner in android programming.
The following is the code of my main class. :- </p>

<p>package com.bullsncows.bnc;</p>

<pre><code>import java.util.Random;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

  public class Startingpoint extends Activity {
     EditText etn1, etn2, etn3, etn4;
     Button bsub;
     TextView errormsg,res;
     Random r = new Random();
     int num = 0;
     boolean guessed = false;
       int count =0;

  /** Called when the activity is first created. */
   @Override
     public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
       setContentView(R.layout.main);
       initializevar();
       // making the computer select a random four digit number
       while(hasDupes(num= (r.nextInt(9000) + 1000)));
       // on clicking the submit button

       bsub.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            String n1 = etn1.getText().toString();
            String n2 = etn2.getText().toString();
            String n3 = etn3.getText().toString();
            String n4 = etn4.getText().toString();
            String cnum = num+"";
            if      (n1.length()==0||n2.length()==0||n3.length()==0||n4.length()==0) {
                errormsg.setText("Fields cannot be left blank");
                errormsg.setTextColor(Color.RED);
                errormsg.setGravity(Gravity.CENTER);
            } else if (n1.equals(n2) || n1.equals(n3) || n1.equals(n4)
                    || n2.equals(n3) || n2.equals(n4) || n3.equals(n4)) {
                errormsg.setText("Please enter distinct number");
                errormsg.setTextColor(Color.RED);
                errormsg.setGravity(Gravity.CENTER);
            }else{
                String guess = n1+n2+n3+n4;
                errormsg.setText("Correct "+ cnum + " "+ guess);
                errormsg.setTextColor(Color.GREEN);
                errormsg.setGravity(Gravity.CENTER);

            do{
                    int bulls = 0;
                    int cows = 0;
                    count++;
                    for(int i= 0;i &lt; 4;i++){
                        if(guess.charAt(i) == cnum.charAt(i)){
                            bulls++;
                        }else if(cnum.contains(guess.charAt(i)+"")){
                            cows++;
                        }
                        else if(bulls == 4){
                            guessed = true;
                            break;
                        }else{
                            res.setText(cows+" Cows and "+bulls+" Bulls.");
                            res.setTextColor(Color.BLUE);
                            res.setGravity(Gravity.CENTER);
                        }
                    }
                }while(!guessed);
                errormsg.setText("You won after "+count+" guesses!");
                errormsg.setTextColor(Color.MAGENTA);
                errormsg.setGravity(Gravity.CENTER);
            }
        }
    });

}

private void initializevar() {
    // TODO Auto-generated method stub
    etn1 = (EditText) findViewById(R.id.etnum1);
    etn2 = (EditText) findViewById(R.id.etnum2);
    etn3 = (EditText) findViewById(R.id.etnum3);
    etn4 = (EditText) findViewById(R.id.etnum4);
    bsub = (Button) findViewById(R.id.bsubmit);
    errormsg = (TextView) findViewById(R.id.tverror);
    res = (TextView) findViewById(R.id.tvres);
}
public static boolean hasDupes(int n){
    boolean[] digs = new boolean[10];
    while(n &gt; 0){
        if(digs[n%10]) return true;
        digs[n%10] = true;
        n/= 10;
    }
    return false;
  }

 }
</code></pre>

<p>The following is the XML coding for the same page :- </p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" &gt;

    &lt;TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Please select the numbers below" /&gt;

    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" &gt;

        &lt;EditText
            android:id="@+id/etnum1"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:maxLength="1" /&gt;

        &lt;EditText
            android:id="@+id/etnum2"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:maxLength="1" /&gt;

        &lt;EditText
            android:id="@+id/etnum3"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:maxLength="1" /&gt;

        &lt;EditText
            android:id="@+id/etnum4"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:maxLength="1" /&gt;
    &lt;/LinearLayout&gt;

    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" &gt;

        &lt;TextView android:id="@+id/tverror" 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"/&gt;
        &lt;TextView android:id="@+id/tvres" 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"/&gt;
    &lt;/LinearLayout&gt;

    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" &gt;

        &lt;Button
            android:id="@+id/bsubmit"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_gravity="fill_vertical"
            android:text="Submit" /&gt;
    &lt;/LinearLayout&gt;

    &lt;TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" &gt;
    &lt;/TableLayout&gt;

        &lt;/LinearLayout&gt;
</code></pre>
