Displaying two random numbers and counting scores for odd and even turns. When one of it reaches to 100, the application stops.
This is my java file of application
public class Board_Play1 extends Activity {
int d=0,a=0,b=0,turn=2;
Random random = new Random();
EditText diceno = (EditText) findViewById(R.id.editText1);
EditText p1 = (EditText) findViewById(R.id.editText2);
EditText p2 = (EditText) findViewById(R.id.editText3);
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.board_play1);
diceno.setText(String.valueOf(d));
p1.setText(String.valueOf(a));
p2.setText(String.valueOf(b));
while(a!=100 && b!=100)
{
if(turn%2==0)
{
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
d=random.nextInt(6)+1;
EditText diceno = (EditText) findViewById(R.id.editText1);
diceno.setText(String.valueOf(d));
}
});
}
else
{
d=random.nextInt(6)+1;
diceno.setText(String.valueOf(d));
}
if(turn%2==0)
a+=d;
else
b+=d;
if(a>100)
a-=d;
if(b>100)
b-=d;
p1.setText(String.valueOf(a));
p2.setText(String.valueOf(b));
turn++;
}
a=0;b=0;
}
}
It doesn't open and give an error saying Unfortunately your app has stopped. Why is this happening? What can I change?