0
顯示兩個隨機數並計算奇數和偶數的分數。當其中一個達到100時,應用程序停止。開始之前Android應用程序崩潰
這是應用
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;
}
}
我的java文件,它不會打開並給出一個錯誤說Unfortunately your app has stopped
。這是爲什麼發生?我可以改變什麼?