Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在AsyncTask执行方法中传递单选按钮代码_Java_Android_Android Asynctask - Fatal编程技术网

Java 在AsyncTask执行方法中传递单选按钮代码

Java 在AsyncTask执行方法中传递单选按钮代码,java,android,android-asynctask,Java,Android,Android Asynctask,我的问题发生在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) findV

我的问题发生在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()”

您应该为每个单选按钮分别查找DViewById

 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);
您可以这样传递值:

如下所示:将男性和女性的值作为布尔值传递

male.isChecked()
female.isChecked()

getCheckedRadioButtonId()


仅返回所选单选按钮的引用

请在问题中而不是在附加图像中发布您的代码和错误。另外,试着问一个问题。那么我如何在execute方法中传递它的值呢?忘记execute方法吧……如果你想传递男性和女性的值,那么我不知道你为什么要使用radio group,因为radio group用于获取单击的单选按钮的值,若你们仍然想得到两者的值,那个么你们需要初始化单选按钮和den,做你们想做的事情