title: Exception setBackgroundColor
body: <p>I have a question for my code, it should change the background color of my Start-Activity. I should choose between blue and red with radio buttons (in RadioGroup). I always get an Error when i click on the RadioButton Red/Blue in the settings menue.</p>
  
  <p>These two lines are wrong?</p>
  
  <pre><code>ChangeToRed(background); background.setBackgroundColor(0x0000FF00);
  </code></pre>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RelativeLayout.setBackgroundColor(int)' on a null object reference
                at com.example.clecks.reaction_game.activity_settings.ChangeToBlue(activity_settings.java:67)
                at com.example.clecks.reaction_game.activity_settings$2.onCheckedChanged(activity_settings.java:42)</p>
  </blockquote>
  
  <p>Here is my java code: </p>
  
  <pre><code>public class activity_settings extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_activity_settings);
      ColorChange();
  }
  
  public void ColorChange() {
      final RelativeLayout background = (RelativeLayout) findViewById(R.id.start);
      final RadioButton ChangeToBlue = (RadioButton) findViewById(R.id.button_blue);
      final RadioButton ChangeToRed = (RadioButton) findViewById(R.id.button_red);
  
  
      final Button button_save = (Button) findViewById(R.id.button_save);
      button_save.setOnClickListener(new Button.OnClickListener() {
          public void onClick(View v) {
              ChangeOption(background);
          }
      });
  
  
      ChangeToBlue.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              ChangeToBlue(background);
          }
      });
  
      ChangeToRed.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              ChangeToRed(background);
          }
  
      });
  
  
  }
  
  public void ChangeOption(RelativeLayout background) {
      if (background.isEnabled()) {
          background.setEnabled(false);
      } else {
          background.setEnabled(true);
  
      }
  }
  
  public void ChangeToBlue(RelativeLayout background) {
      background.setBackgroundColor(Color.BLUE);
      background.invalidate();
  
  }
  public void ChangeToRed(RelativeLayout background) {
      background.setBackgroundColor(Color.RED);
      background.invalidate();
  
  }
  
  
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_activity_settings, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }}
  </code></pre>
  
  <p>XML Code:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  tools:context="com.example.clecks.reaction_game.activity_settings"&gt;
  
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="Einstellungen"
          android:id="@+id/textView2"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:id="@+id/textView3"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Singalton"
          android:id="@+id/textView4"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;RadioGroup
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="New RadioButton"
              android:id="@+id/radioButton"
              android:layout_gravity="center_horizontal"
              android:checked="false" /&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="New RadioButton"
              android:id="@+id/radioButton2"
              android:layout_gravity="center_horizontal" /&gt;
      &lt;/RadioGroup&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/textView5"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Hintergrundfarbe"
          android:id="@+id/textView6"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;RadioGroup
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:id="@+id/RadioGroup_Color"&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Rot"
              android:id="@+id/button_red"
              android:checked="false"
              android:layout_gravity="center_horizontal" /&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Blau"
              android:id="@+id/button_blue"
              android:checked="false"
              android:layout_gravity="center_horizontal" /&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Grün"
              android:id="@+id/button_green"
              android:checked="false"
              android:layout_gravity="center_horizontal" /&gt;
      &lt;/RadioGroup&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/textView7"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Spielmodus"
          android:id="@+id/textView8"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;RadioGroup
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Handy"
              android:id="@+id/radioButton6"
              android:layout_gravity="center_horizontal"
              android:checked="false" /&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Wii-Mote"
              android:id="@+id/radioButton7"
              android:layout_gravity="center_horizontal"
              android:checked="false" /&gt;
      &lt;/RadioGroup&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/textView9"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/textView10"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Speichern"
          android:id="@+id/button_save"
          android:layout_gravity="center_horizontal" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>