-3
このコードをif文で実行します。私のアプリでボタンを押すとクラッシュします。なぜ私はif文を削除しても問題ないテキストを出力する理由を理解できません。基本的なアンドロイドのif文の強制終了
public void onButtonClickGuess (View v) {
EditText Guess1 = (EditText)findViewById(R.id.editText);
TextView result1 = (TextView)findViewById(R.id.textView2);
//turn r into a random number between 1 and 10 (inclusive)
Random r = new Random();
int i1 = r.nextInt(10 - 1) + 1;
int guess1 = Integer.parseInt(Guess1.getText().toString());
if (i1 > guess1){
result1.setText("Too Low");
}else if (i1<guess1){
result1.setText("Too High");
}else (i1 == guess1){
result1.setText("NICE GUESS!!");
}
}
logcatはありますか?どのようなエラーが表示されますか? –
あなたの 'else'ステートメントを見てください。構文エラーがあります。 'else'ステートメントに条件を記述しません。 –
今すぐlogcatを探しています。 – TwizzleBizzle