2 回答

TA貢獻1802條經(jīng)驗 獲得超5個贊
注意數(shù)據(jù)類型:
在A班,你有:
score=idx1+idx2; Intent intent = new Intent(A.this, B.class); intent.putExtra("message", score); startActivity(intent);
這score
是 int,但是在 B 類中:
Bundle extras = getIntent().getExtras(); if(extras!=null) { String m= extras.getString("message"); totalscore=Integer.parseInt(m); }
您正試圖將其作為字符串獲取,但它為空,因此應(yīng)用程序崩潰了。
所以請將其更改為:
Bundle extras = getIntent().getExtras(); if(extras!=null) { totalscore = extras.getInt("message"); }
然后再試一次

TA貢獻1853條經(jīng)驗 獲得超6個贊
試試這個例子
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_male"
android:checked="true" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_female" />
</RadioGroup>
在你的A班
radioSexGroup = (RadioGroup) findViewById(R.id.radioSex);
btnDisplay = (Button) findViewById(R.id.btnDisplay);
btnDisplay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// get selected radio button from radioGroup
int selectedId = radioSexGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioSexButton = (RadioButton) findViewById(selectedId);
Toast.makeText(MyAndroidAppActivity.this,
radioSexButton.getText(), Toast.LENGTH_SHORT).show();
}
});
發(fā)布崩潰報告以了解有關(guān)您的問題的更多信息
添加回答
舉報