Android Build a Simple Android App with Java Improving Our Code Dynamically Changing the Background Color

[Solved] My app crashes when I change the background color

When I try to change the Background Color my App Builds without errors but when I try to run the app it just crashes. Here is the code.
package com.withur.facttest;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    // Declare our View variables
    private FactBook factBook = new FactBook();

    private RelativeLayout relativeLayout;
    private TextView factTextView;
    private Button showFactButton;

    protected void onCreate(Bundle savedInstanceState) {

        relativeLayout = findViewById(;
        factTextView = findViewById(;
        showFactButton = findViewById(;
        View.OnClickListener listener = new View.OnClickListener() {
            public void onClick(View v) {

                //Update the screen with a new fact


Edit: The issue was that I changed the layout to Constraint and didn't realize.

Hi Codrin. Could you copy/paste the error message you get in your logcat please? (using the "show only selected application" filter). Thanks

Oh Lauren Moineau that helped! I was using by accident ConstraintLayout because Relative Layout was throwing everything in the corner for me.

Awesome Codrin Postu ! I'm glad you fixed it :)