我的问题是在尝试传递男性和女性
的值时在background.excute方法中发生的name = (EditText) findViewById(R.id.NameTxt);
age = (EditText) findViewById(R.id.Agetext);
gender = (RadioGroup) findViewById(R.id.radio);
int id = gender.getCheckedRadioButtonId();
male = (RadioButton) findViewById(id);
female = (RadioButton) findViewById(id);
public void INSERT (View v){
MainBackground mainBackground=new MainBackground(this,this);
mainBackground.execute(name.getText().toString(),age.getText().toString(),
male.getText().toString(),female.getText().toString());
,错误是: 引起:java.lang.NullPointerException:尝试调用虚方法' java.lang.CharSequence android.widget.RadioButton.getText()'在空对象引用上
答案 0 :(得分:1)
你应该为每个单选按钮单独找到ViewById。
function getDistance(origin, destination) {
var distanceDuration = [];
..
distanceDuration[0] = results[j].distance.text;
distanceDuration[1] = results[j].duration.text;
return distanceDuration;
}
var addressElement = document.getElementById('address-autocomplete');
addressElement.addEventListener('change', function() {
var origin = 'Kraków, Poland';
var destination = addressElement.value;
var distanceDuration = getDistance(origin, destination);
console.log('distanceDuration: ', typeof distanceDuration); // -> object
console.log('distanceDuration: ', distanceDuration);
//console.log('distanceDuration: ', distanceDuration[0]); // -> undefined
..
}, false);
你可以传递这样的值:
像这样:将男性和女性的值传递为布尔值。
male = (RadioButton) findViewById(R.id.male);// give id to male radio button as male if not give and similarly female for female button
female = (RadioButton) findViewById(R.id.female);
答案 1 :(得分:0)
radio.getCheckedRadioButtonId();
仅返回Selected Radio按钮的引用