I encounter a crash "java.lang.NullPointerException" whenever I run my
app. please help:

------------------------------------------------------------------------------------------------------------------------------
package Botton.radio;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class RadioButtonWidget extends Activity {
    public class ClearButtonListener implements OnClickListener {
        @Override
        public void onClick(View aArg0) {
            mRadioGroup.clearCheck();
            mTextView.setText(getString(R.string.selection) + " "
                    + getString(R.string.none));
        }
    }

    public class RadioGroupListener implements OnCheckedChangeListener
{
        @Override
        public void onCheckedChanged(RadioGroup radioButton,
                int idOfSelectedRadioButton) {
            if (idOfSelectedRadioButton != -1) {
                mRadioButton = (RadioButton) 
findViewById(idOfSelectedRadioButton);
                mTextView.setText(getString(R.string.selection) + " "
                        + mRadioButton.getText());
            }
        }

    }

    private Button mClearButton;
    private RadioButton mRadioButton;
    private RadioGroup mRadioGroup;
    private TextView mTextView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        addWidgetListeners();
        setWidgetReferences();

    }

    private void addWidgetListeners() {
        ClearButtonListener aListener = new ClearButtonListener();
        RadioGroupListener rListener = new RadioGroupListener();
        mClearButton.setOnClickListener(aListener);
        mRadioGroup.setOnCheckedChangeListener(rListener);
    }

    private void setWidgetReferences() {
        mClearButton = (Button) findViewById(R.id.clear);
        mRadioGroup = (RadioGroup) findViewById(R.id.menu);
        mTextView = (TextView) findViewById(R.id.choice);
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to