title: Android read state of radiobuttons in custom dialog [update -> How to read from a custom dialog?]
body: <p>-- updated question --</p>
  
  <p>I can't read any data from my custom dialog, at first i thought it was just the radiobuttons, so i thought lets continue the project so i give a default value for the testing purpose.</p>
  
  <p>Even after i've tried to read from the EditText, i get nullpointerexceptions.</p>
  
  <p>Any idea what I'm doing wrong here?? (below is the XML + code and in the comments below i've shown what i did with the EditText)</p>
  
  <p>-- old question --</p>
  
  <p>So, i've used multiple sources to combine the layout/check functions I am using now.</p>
  
  <p>When i'm trying to see what radiobutton was selected i keep getting nullpointer errors, so i've searched in here and i have added some test to see if i could get results by seeing what was set via radiogroup (instead of individual buttons).</p>
  
  <p>Let me show you what i've done/tried so far.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      private RadioGroup rbs; //added for test
      private RadioButton rb1;
      private RadioButton rb2;
      private RadioButton rb3;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>        final Dialog dialog = new Dialog(this);
          dialog.setContentView(R.layout.connectpopup);
          dialog.setTitle("Quick Connect");
          dialog.setCancelable(true);
          Button button = (Button) dialog.findViewById(R.id.connect);
          button.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  rbs = (RadioGroup) findViewById(R.id.widget33); //added for test
                  rb1 = (RadioButton) findViewById(R.id.nmdc);
                  rb2 = (RadioButton) findViewById(R.id.adc);
                  rb3 = (RadioButton) findViewById(R.id.adcs);
                  //RadioGroup.getCheckedRadioButtonId()
                  Log.v("test", ""+rbs.getCheckedRadioButtonId()); //this doesn't give results either same nullpointer error
                  if (rb1.isChecked() == true) { // these check for checked makes the app stop.
                      Toast.makeText(getApplicationContext(), rb1.getText(), 5).show();
                  }
                  if (rb2.isChecked() == true) {
                      Toast.makeText(getApplicationContext(), rb2.getText(), 5).show();
                  }
                  if (rb3.isChecked() == true) {
                      Toast.makeText(getApplicationContext(), rb3.getText(), 5).show();
                  }
                  dialog.dismiss();
              }
          });
          dialog.show();
  </code></pre>
  
  <p>and the xml file i'm calling from:
  <code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      android:id="@+id/quickconnectpopup"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      xmlns:android="http://schemas.android.com/apk/res/android"
      &gt;
      &lt;TextView
          android:id="@+id/help"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Please enter the address.\r\nSelect the protocol.\r\nEnter your nickname."
          &gt;
      &lt;/TextView&gt;
      &lt;EditText
          android:id="@+id/hubaddress"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="some.address.com:411"
          android:textSize="18sp"
          &gt;
      &lt;/EditText&gt;
      &lt;RadioGroup
          android:id="@+id/widget33"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          &gt;
          &lt;RadioButton
              android:id="@+id/nmdc"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="protocol1"
              &gt;
          &lt;/RadioButton&gt;
          &lt;RadioButton
              android:id="@+id/adc"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="prototocol2"
              &gt;
          &lt;/RadioButton&gt;
          &lt;RadioButton
              android:id="@+id/adcs"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="protocol3"
              &gt;
          &lt;/RadioButton&gt;
      &lt;/RadioGroup&gt;
      &lt;EditText
          android:id="@+id/nickname"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Nick"
          android:textSize="18sp"
          &gt;
      &lt;/EditText&gt;
      &lt;Button
          android:id="@+id/connect"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Connect"
          &gt;
      &lt;/Button&gt;
  &lt;/LinearLayout&gt;</code></p>
  
  <p>The error shows up when i'm trying to read (one or two of) this lines (same line was shown since i've added log.v lateron)</p>
  
  <pre><code>10:26:44.814    1124    ERROR   AndroidRuntime  Uncaught handler: thread main exiting due to uncaught exception
  10:26:44.845    1124    ERROR   AndroidRuntime  java.lang.NullPointerException
  10:26:44.845    1124    ERROR   AndroidRuntime      at nl.my.project.MainActivity$1.onClick(MainActivity.java:89)
  
  Log.v("test", ""+rbs.getCheckedRadioButtonId()); //this doesn't give results either same nullpointer error
  if (rb1.isChecked() == true) { // these check for checked makes the app stop.
  </code></pre>
  
  <p>So to state the exact question again, how could i retrieve the selected radiobutton.</p>
  
  <p>in example show in Log.v("selected button:", variable); = 
  <code>Verbose    Androidblabla    radio1</code> </p>