Android中的Radiogroup出现问题

Android中的Radiogroup出现问题,android,radio-group,Android,Radio Group,我在安卓系统的一个放射组遇到了麻烦,我测试了所有东西,但似乎都不起作用 这是我的密码: 受保护的void onCreateBundle savedInstanceState{ super.onCreatesavedInstanceState; 放射组rg=放射组findViewByIdR.id.RadioGroup 1; setContentViewR.layout.activity_问题; titre=TextView findViewByIdR.id.textView1; 问题=TextV

我在安卓系统的一个放射组遇到了麻烦,我测试了所有东西,但似乎都不起作用

这是我的密码:

受保护的void onCreateBundle savedInstanceState{ super.onCreatesavedInstanceState; 放射组rg=放射组findViewByIdR.id.RadioGroup 1; setContentViewR.layout.activity_问题; titre=TextView findViewByIdR.id.textView1; 问题=TextView findViewByIdR.id.textView2; image=ImageView findviewbydr.id.imageView1; rep2=RadioButton findViewByIdR.id.radio1; rep3=RadioButton findViewByIdR.id.radio2; rep4=RadioButton findViewByIdR.id.radio3; count=TextView findViewByIdR.id.textView4; 计数器=TextView findViewByIdR.id.textView3; 计数为1/5; 试一试{ 结果=new RequestTask.executehttp://tv3.orangeadd.com/surveys/current?owner=ofc&user=yasser&category=-1.获得; }捕捉中断异常e{ //TODO自动生成的捕捉块 e、 打印跟踪; }捕获执行异常{ //TODO自动生成的捕捉块 e、 打印跟踪; } GsonBuilder gsonb=新的GsonBuilder; Gson Gson=gsonb.create; s=新调查; s=gson.fromJsonresult,Surveyentity.class.Survey; titre.setTexts.getName; question.setTexts.getListquest.get0.getLabel; 毕加索.withQuestions.this.loads.getListquest.get0.getUrl.intoimage; rep1.setTexts.getListquest.get0.getList.get0.getLabel; rep2.setTexts.getListquest.get0.getList.get1.getLabel; rep3.setTexts.getListquest.get0.getList.get2.getLabel; rep4.setTexts.getListquest.get0.getList.get3.getLabel; 开始=新的倒计时。getListquest.get0.getTimeout,1000{ 已完工的百万米长的公共空间{ counter.settexts剩余时间:+millisuntillfinished/1000; } 公开无效完成{ 柜台,完毕!; 前链问题; } }.开始; rg.setOnCheckedChangeListener新建OnCheckedChangeListener{ @凌驾 在checkedChangedRadioGroup组、int checkedId上的公共void{ //查找所选的单选按钮 ifcheckedId==R.id.0{ Toast.makeTextgetApplicationContext,选项:无提示, Toast.LENGTH_SHORT.show; }else ifcheckedId==R.id.radio1{ Toast.makeTextgetApplicationContext,选项:声音, Toast.LENGTH_SHORT.show; }否则{ Toast.makeTextgetApplicationContext,选项:振动, Toast.LENGTH_SHORT.show; } } }; } 问题出在以下行:rg.setOnCheckedChangeListenernew OnCheckedChangeListener

rg为空,因为在调用setContentView之前尝试从布局获取视图。因此,交换两行:

setContentView(R.layout.activity_questions);
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);