title: Can't change the background color through java
body: <p>Im trying to make a settings activity from which the user can change the background color of the main activity... here is my java code, everything with the xml is fine 
  the target activity to change the background to is not the one with the radio buttons</p>
  
  <pre><code>public class SettingsActivity extends AppCompatActivity {
  
  
  ConstraintLayout loginContainer;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_settings);
      loginContainer = findViewById(R.id.loginContainer);
  }
  
  public void onColorRadioClicked(View view) {
      // Is the button now checked?
      boolean checked = ((RadioButton) view).isChecked();
      RadioButton btn1 = findViewById(R.id.colorRadio1);
      RadioButton btn2 = findViewById(R.id.colorRadio2);
      RadioButton btn3 = findViewById(R.id.colorRadio3);
  
      // Check which radio button was clicked
      switch(view.getId()) {
          case R.id.colorRadio1:
              if (checked)
                  btn2.setChecked(false);
                  btn3.setChecked(false);
                  loginContainer.setBackgroundColor(getResources().getColor(R.color.wallBack1));
                  break;
          case R.id.colorRadio2:
              if (checked)
                  btn1.setChecked(false);
                  btn3.setChecked(false);
                  loginContainer.setBackgroundColor(getResources().getColor(R.color.wallBack2));
              break;
          case R.id.colorRadio3:
              if (checked)
                  btn1.setChecked(false);
                  btn2.setChecked(false);
                  loginContainer.setBackgroundColor(getResources().getColor(R.color.wallBack3));
              break;
      }
  }
  
  }
  </code></pre>
  
  <p>whenever i click a radio button, at first (without trying to change the color) everything worked but now after ive added those lines, everytime i click it crashes saying it couldnt execute method for android:onClick</p>
  
  <p>the error in the Run section</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                Process: com.example.roeie.renote, PID: 2590
                java.lang.IllegalStateException: Could not execute method for android:onClick
                    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                    at android.view.View.performClick(View.java:5610)
                    at android.widget.CompoundButton.performClick(CompoundButton.java:122)
                    at android.view.View$PerformClick.run(View.java:22260)
                    at android.os.Handler.handleCallback(Handler.java:751)
                    at android.os.Handler.dispatchMessage(Handler.java:95)
                    at android.os.Looper.loop(Looper.java:154)
                    at android.app.ActivityThread.main(ActivityThread.java:6077)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                 Caused by: java.lang.reflect.InvocationTargetException
                    at java.lang.reflect.Method.invoke(Native Method)
                    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                    at android.view.View.performClick(View.java:5610) 
                    at android.widget.CompoundButton.performClick(CompoundButton.java:122) 
                    at android.view.View$PerformClick.run(View.java:22260) 
                    at android.os.Handler.handleCallback(Handler.java:751) 
                    at android.os.Handler.dispatchMessage(Handler.java:95) 
                    at android.os.Looper.loop(Looper.java:154) 
                    at android.app.ActivityThread.main(ActivityThread.java:6077) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.constraint.ConstraintLayout.setBackgroundColor(int)' on a null object reference
                    at com.example.roeie.renote.SettingsActivity.onColorRadioClicked(SettingsActivity.java:34)
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
                    at android.view.View.performClick(View.java:5610) 
                    at android.widget.CompoundButton.performClick(CompoundButton.java:122) 
                    at android.view.View$PerformClick.run(View.java:22260) 
                    at android.os.Handler.handleCallback(Handler.java:751) 
                    at android.os.Handler.dispatchMessage(Handler.java:95) 
                    at android.os.Looper.loop(Looper.java:154) 
                    at android.app.ActivityThread.main(ActivityThread.java:6077) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
  </code></pre>
  
  <p>The Radio Buttons XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.example.roeie.renote.SettingsActivity"
  android:background="@color/wallBack1"&gt;
  
  &lt;RadioButton
      android:onClick="onColorRadioClicked"
      android:id="@+id/colorRadio1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="16dp"
      android:layout_marginTop="40dp"
      android:text="RadioButton"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintTop_toTopOf="parent" /&gt;
  
  &lt;RadioButton
      android:onClick="onColorRadioClicked"
      android:id="@+id/colorRadio2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="16dp"
      android:text="RadioButton"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/colorRadio1" /&gt;
  
  &lt;RadioButton
      android:onClick="onColorRadioClicked"
      android:id="@+id/colorRadio3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="16dp"
      android:text="RadioButton"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/colorRadio2" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>the xml of the activity that needs to be changed is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/loginContainer"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/wallBack1"
  tools:context="com.example.roeie.renote.LoginActivity"&gt;
  
  &lt;TextView
  
      android:id="@+id/textView"
      android:layout_width="350dp"
      android:layout_height="wrap_content"
      android:text="RENOTE"
      android:textAlignment="center"
      android:textColor="@color/fui_bgGoogle"
      android:textSize="80sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.223" /&gt;
  
  &lt;Button
      android:id="@+id/signInBtn"
      android:layout_width="230dp"
      android:layout_height="wrap_content"
      android:layout_marginBottom="8dp"
      android:background="@drawable/button_shape_1"
      android:onClick="signInClick"
      android:text="Sign In"
      android:textColor="@color/wallBack1"
      app:layout_constraintBottom_toTopOf="@+id/signOutBtn"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.977" /&gt;
  
  &lt;Button
      android:id="@+id/signOutBtn"
      android:layout_width="230dp"
      android:layout_height="wrap_content"
      android:background="@drawable/button_shape_1_rev"
      android:onClick="signOutClick"
      android:text="Sign Out"
      android:textColor="#FFFFFF"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.928" /&gt;
  
  &lt;Button
      android:id="@+id/button2"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_marginEnd="20dp"
      android:layout_marginTop="28dp"
      android:background="@drawable/ic_action_settings_white"
      android:onClick="settingsBtnClick"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent" /&gt;
  &lt;!--android:background="@drawable/button_shape_1"--&gt;
  </code></pre>
  
  <p></p>