RadioGroup.check(int) not working

I'm having a little trouble with RadioGroups. I created a blank radiogroup in layout. And then filled it with equalizer presets in the code. Then I tried to set one of the option using radiogroup.check(1). But it threw a null pointer exception.

Below is the code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.equalizer);
    //rgEqualizer = (RadioGroup) findViewById(R.id.rgEqualizerPreset);
    mPlayer = new MediaPlayer();
    mEqualizer = new Equalizer(0, AuID);
    rgEqualizer = new RadioGroup(this);
    radioButtonList = new ArrayList<RadioButton>();
    layoutParams = new RadioGroup.LayoutParams(
        RadioGroup.LayoutParams.FILL_PARENT,
        RadioGroup.LayoutParams.WRAP_CONTENT);

    fillRadioGroupWithRadioButtons();
    rgEqualizer.setEnabled(true);
    rgEqualizer.setOnCheckedChangeListener(this);
    addContentView(rgEqualizer, layoutParams);
    loadPresetsettings();
}
private void fillRadioGroupWithRadioButtons() {
    Short noPresets = mEqualizer.getNumberOfPresets();
    short i = 0;
    while (i < noPresets) {
        RadioButton rb = new RadioButton(this);
        rb.setText(mEqualizer.getPresetName(i));
        rgEqualizer.addView(rb, layoutParams);
        i++;
    }
}
private void loadPresetsettings() { 
    rgEqualizer.check(1);
}

It seems like even after adding the child radio buttons fillRadioGroupWithRadioButtons(), there are no childs added in radiogroup. What am I missing/

Thanks in advance

Answers


Done with a work around I guess

        RadioButton o = (RadioButton) rgEqualizer.getChildAt(1);
        o.setChecked(true);

You have defined rgEqualizer two times in your code.

    rgEqualizer = (RadioGroup) findViewById(R.id.rgEqualizerPreset);   <----- Here
    mPlayer = new MediaPlayer();
    mEqualizer = new Equalizer(0, AuID);
    rgEqualizer = new RadioGroup(this);   <---- And here //Delete this

Need Your Help

GWT - failure on async method call

java gwt smartgwt

What is the reason why the onFailure(...) method is called when I do a async method call? The console output says always "ERROR!!!!".