title: Getting a null pointer exception when finding RadioGroup
body: <p>I seem to be getting a NULL POINTER exception when I start my <code>setting</code> activity. All I'm doing is trying to check whether a <code>RadioGroups</code> radio buttons change and when I initialize a RadioGroup object it crashes. </p>
  
  <p>Logcat messages:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
  
  at com.example.pckg.Setting.&lt;init&gt;(Setting.java:14)
  </code></pre>
  
  <p>Here is my Java code:</p>
  
  <pre><code>import android.widget.RadioGroup;
  import android.widget.RadioGroup.OnCheckedChangeListener;
  
  
  public class Setting extends Main {
      // Radio Groups declaration LINE 14 IS BELOW V
      RadioGroup appTileTheme = (RadioGroup) findViewById(R.id.radGroupTileColour);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.setting);
  
          checkIfThemeChanged();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
  
          return true;
      }
  
      public void checkIfThemeChanged() {
  
          appTileTheme.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
              public void onCheckedChanged(RadioGroup group, int checkedId) {
  //              Log.d("chk", "id" + checkedId);
  
                  if (checkedId == R.id.radTheme1) {
                      setThemeSharedPreferences(1);
  
                  } else if (checkedId == R.id.radTheme2) {
                      setThemeSharedPreferences(2);
                  }
  
              }
  
          });
      }
  </code></pre>
  
  <p>Here is my XML: </p>
  
  <pre><code>&lt;TextView
          android:id="@+id/txtGridTileColour"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Grid Tile Colour"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:layout_marginTop="15dp" /&gt;
  
      &lt;RadioGroup
          android:id="@+id/radGroupTileColour"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:orientation="horizontal" &gt;
  
          &lt;RadioButton
              android:id="@+id/radTheme1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:checked="true"
              android:text="Normal" /&gt;
  
          &lt;RadioButton
              android:id="@+id/radTheme2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Cool Gradient" /&gt;
      &lt;/RadioGroup&gt;
  </code></pre>