I have a radio group in android containing 3 options. Plus i also have a button named checked. I want to select option 1 when i click the button “checked”. Here’s what i am doing:
RadioGroup options;
RadioButton rb;
TextView txt;
CharSequence userMsg;
Button checked;
int id;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
options=(RadioGroup)findViewById(R.id.options);
txt=(TextView)findViewById(R.id.txt);
options.setOnCheckedChangeListener(new android.widget.RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
rb=(RadioButton)findViewById(checkedId);
userMsg=rb.getText();
txt.setText(userMsg);
}
});
checked.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
options.check(1);
}
});
}
}
It gives me null pointer exception error.Please help!
Write this in your Button
onClickfunction