2 回答

TA贡献1802条经验 获得超5个赞
注意数据类型:
在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); }
您正试图将其作为字符串获取,但它为空,因此应用程序崩溃了。
所以请将其更改为:
Bundle extras = getIntent().getExtras(); if(extras!=null) { totalscore = extras.getInt("message"); }
然后再试一次

TA贡献1853条经验 获得超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();
}
});
发布崩溃报告以了解有关您的问题的更多信息
添加回答
举报