Retrieve value from radioButtons in alertDialog <p>I want to retrive the value from the radio buttons. I am doing the below code. But when I click OK button of alert dialog my app is force closed. why is is so. A I not retriving the value properly</p> <pre><code> final SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE); if (settings.getBoolean("isFirstRun", true)) { LayoutInflater li = LayoutInflater.from(this); View promptsView = li.inflate(R.layout.prompts, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setView(promptsView); final EditText userInput = (EditText) promptsView .findViewById(R.id.editTextDialogUserInput); final RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { int selectedId = radioGroup.getCheckedRadioButtonId(); // find the radiobutton by returned id final RadioButton radioButton = (RadioButton) findViewById(selectedId); String radio_value = radioButton.getText().toString(); data_mode=Integer.parseInt(radio_value); String value = userInput.getText().toString(); currentIntervalChoice=Integer.parseInt(value); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("isFirstRun", false); editor.putInt("currentIntervalChoice", currentIntervalChoice); editor.putInt("data_mode", data_mode); editor.commit(); dialog.dismiss(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } </code></pre> <p>prompt.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Type Interval : " android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;EditText android:id="@+id/editTextDialogUserInput" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="number" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton" /&gt; &lt;RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton" /&gt; &lt;/RadioGroup&gt; &lt;/LinearLayout&gt; </code></pre>