title: null pointer exception on radio group
body: <p>I am trying to make a popup window in an activity. The popup window shows up when we click a button in the activity. The layout for popup window is to show a radio group containing 4 radio buttons, a button and a seek bar and has to return a value to the main activity based on the selected radio button when the button in the pop up window is pressed.</p>
  
  <p>When i run the app and open the pop up window it is giving we this error:
  "java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)' on a null object reference "</p>
  
  <p>The code for my main activity is:</p>
  
  <pre><code>public class CustomMenuActivity extends Activity
  {
  
  String ingredientName;
  String ingredientQuantity;
  private PopupWindow pw;
  Button setQuantity;
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_custom_menu);
  
      setQuantity = (Button) findViewById(R.id.btnSetQty);
  
      setQuantity.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v)
          {
              initiatePopupWindow();
          }
      });
  
  }
  
  private void initiatePopupWindow()
  {
  
      try {
          //We need to get the instance of the LayoutInflater, use the context of this activity
          LayoutInflater inflater = (LayoutInflater) CustomMenuActivity.this
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          //Inflate the view from a predefined XML layout
          View layout = inflater.inflate(R.layout.set_quantity_popup,
                  (ViewGroup) findViewById(R.id.popupElementid));
          // create a 600px width and 570px height PopupWindow
          pw = new PopupWindow(layout, 600, 570, true);
          // display the popup in the center
          pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
  
          RadioGroup radioGroup;
  
          radioGroup = (RadioGroup) findViewById(R.id.radioGroupid);
  
          final String[] tempQtyVar = new String[1];
  
  
          radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(RadioGroup group, int checkedId) {
                  switch (checkedId){
                      case R.id.rbqty30id:
                          tempQtyVar[0] = "30";
                          break;
                      case R.id.rbqty60id:
                          tempQtyVar[0] = "60";
                          break;
                      case R.id.rbqty90id:
                          tempQtyVar[0] = "90";
                          break;
                      case R.id.rbqtycutomid:
                          tempQtyVar[0] = "120";
                          break;
                  }
              }
          });
  
          Button setQtyBtn = (Button) layout.findViewById(R.id.buttonOkSetQtyid);
          setQtyBtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  ingredientQuantity = tempQtyVar[0];
                  Toast.makeText(getApplicationContext(),ingredientQuantity,Toast.LENGTH_LONG).show();
                  pw.dismiss();
              }
          });
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  
  }
  </code></pre>
  
  <p>The layout.xml for my pop up window is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:background="#fd050505"
      android:padding="30dp"
      android:id="@+id/popupElementid"&gt;
      &lt;RelativeLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:id="@+id/relativeLayout"&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="SET QUANTITY"
              android:textColor="#84e9e6"
              android:textSize="20sp"
              android:layout_centerHorizontal="true"
              android:layout_marginTop="20dp"
              android:textStyle="bold"
              android:id="@+id/popupTitleid"/&gt;
          &lt;LinearLayout
              android:layout_width="600dp"
              android:layout_height="wrap_content"
              android:layout_below="@+id/popupTitleid"
              android:orientation="horizontal"
              android:background="@drawable/btn_rounded_boarder"
              android:layout_centerHorizontal="true"
              android:layout_marginTop="20dp"&gt;
              &lt;RadioGroup
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/radioGroupid"
                  android:layout_marginTop="20dp"
                  android:layout_marginBottom="20dp"
                  android:orientation="horizontal"
                  &gt;
                  &lt;RadioButton
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text=" 30ml "
                      android:textColor="#84e9e6"
                      android:id="@+id/rbqty30id"
                      android:checked="true" /&gt;
                  &lt;RadioButton
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:textColor="#84e9e6"
                      android:text=" 60ml "
                      android:id="@+id/rbqty60id" /&gt;
                  &lt;RadioButton
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:textColor="#84e9e6"
                      android:text=" 90ml "
                      android:id="@+id/rbqty90id" /&gt;
                  &lt;RadioButton
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:textColor="#84e9e6"
                      android:text=" Custom Value "
                      android:id="@+id/rbqtycutomid"
                      /&gt;
              &lt;/RadioGroup&gt;
          &lt;/LinearLayout&gt;
          &lt;LinearLayout
              android:layout_width="600dp"
              android:layout_height="wrap_content"
              android:layout_marginTop="50dp"
              android:layout_centerHorizontal="true"&gt;
              &lt;SeekBar
                  android:id="@+id/customqtySBid"
                  android:layout_height="fill_parent"
                  android:layout_width="600dp"
                  android:textColor="#84e9e6"
                  android:layout_marginLeft="30dp"
                  android:layout_marginRight="30dp"
                  android:layout_marginTop="150dp"
                  android:paddingBottom="10dp"/&gt;
          &lt;/LinearLayout&gt;
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:layout_centerHorizontal="true"&gt;
              &lt;Button
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/buttonOkSetQtyid"
                  android:textColor="#84e9e6"
                  android:text="OK"
                  android:background="@drawable/btn_rounded_boarder"
                  android:layout_marginTop="275dp"/&gt;
          &lt;/LinearLayout&gt;
  
      &lt;/RelativeLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I tried looking for answer online but didn't really find solution specific to my problem. Please suggest any solutions.
  Thanks in advance. </p>