いくつかの Android アクティビティを介して 2 つの変数を渡そうとしています。それらの 1 つは、最後のページで null として表示され続けます。
最初のアクティビティ:
Intent intent= new Intent(RoundOptionActivity.this, MoveOptionActivity.class);
intent.putExtra("numRounds", "5");
startActivity(intent);
2 番目のアクティビティ:
Bundle extras = getIntent().getExtras();
if(extras !=null) {
numRounds = Integer.parseInt(extras.getString("numRounds"));
}
.........
Intent intent = new Intent(MoveOptionActivity.this, MoveActivity.class);
intent.putExtra("numRounds", numRounds);
intent.putExtra("playerChoice", playerChoice);
startActivity(intent);
(この時点で LogCat に numRounds を出力したところ、null ではなく正しい数値に設定されていたことに注意してください)
3 番目のアクティビティ:
Bundle extras = getIntent().getExtras();
if(extras !=null) {
playerChoice = Integer.parseInt(extras.getString("playerChoice"));
numRounds = Integer.parseInt(extras.getString("numRounds"));
}
この時点で、numRounds を整数に解析しようとした行でアプリケーションがクラッシュし、null 値を解析できないという NumberFormatException が発生します。playerChoice には問題はなく、numRounds だけです。playerChoice とまったく同じ方法で numRounds を処理しようとしましたが、何も機能しないようです。どうしたの?D: