Android Studio: Canvas added to activity_main.xml crashes app : My problem:

I have been trying to make an app where a ball bounces around based on orientation change. I had some problems with that so I started this project differently. The ball moves up/down/right/left when I use arrow keys. The ball itself moves great, the text is seen on the screen (at least I saw it at one point!) but I can't get these two on the screen together.

**Every time I add BouncingBall to activity_main.xml the app starts to crash and nothing is seen on the screen.** When I remove the BouncingBall from activity_main.xml, I see the ball again and also can move it but cannot see the text. What seems to be the officer, problem? My brain isn't working properly anymore and there might be something funny in the code that I just don't see.


**activity_main.xml**:

    <?xml version="1.0" encoding="utf-8"?>
    <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.maija.pomppupallo.MainActivity">

    <com.example.maija.pomppupallo.BouncingBallView
        android:id="@+id/bouncingBallView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/hellou"
        android:layout_width="195dp"
        android:layout_height="70dp"
        android:text="@string/hello"
        android:textColor="@color/colorAccent"
        android:textSize="30sp"
        android:translationZ="100dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textorientation"
        android:layout_width="287dp"
        android:layout_height="50dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:text="@string/orientation"
        android:textColor="@android:color/holo_red_dark"
        android:textSize="30sp"
        android:translationZ="100dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.506"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>

**Main Activity.java**:

    package com.example.maija.pomppupallo;

    import android.app.Activity;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.TextView;

    public class MainActivity extends AppCompatActivity {

    TextView tv1, tv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);
        setContentView(R.layout.activity_main);

        View BouncingBallView = new BouncingBallView(this);
        setContentView (BouncingBallView);

    }
    }

**BouncingBallView.java**:

    package com.example.maija.pomppupallo;

    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.RectF;
    import android.view.KeyEvent;
    import android.view.View;

    public class BouncingBallView extends View {

    private int xMin = 0;
    private int xMax;
    private int yMin = 0;
    private int yMax;
    private float ballRadius = 130;
    private float ballX = ballRadius + 20;
    private float ballY = ballRadius + 40;
    private float ballSpeedX = 0;
    private float ballSpeedY = 0;
    private RectF ballBounds;
    private Paint paint;

    public BouncingBallView(Context context) {
        super (context);
        ballBounds = new RectF();
        paint = new Paint();

        this.setFocusable(true);
        this.requestFocus();
    }



    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {

        switch (keyCode){
            case KeyEvent.KEYCODE_DPAD_RIGHT:
            ballSpeedY=0;
                if (ballSpeedX > 0) {
                    ;
                }
                else ballSpeedX = 20;
                break;

            case KeyEvent.KEYCODE_DPAD_LEFT:
            ballSpeedY=0;
                if (ballSpeedX < 0) {
                    ;
                }
                else ballSpeedX = -20;
                break;

            case KeyEvent.KEYCODE_DPAD_UP:
            ballSpeedX=0;
                if (ballSpeedY < 0) {
                    ;
                }
                else ballSpeedY = -20;
            break;

            case KeyEvent.KEYCODE_DPAD_DOWN:
            ballSpeedX=0;
                if (ballSpeedY > 0) {
                    ;
                }
                else ballSpeedY = 20;
            break;

            case KeyEvent.KEYCODE_DPAD_CENTER:
                ballSpeedX=0;
                ballSpeedY=0;
                break;

            case KeyEvent.KEYCODE_A:
                float maxRadius = (xMax>yMax) ? yMax/2*0.9f : xMax/2*0.9f;
                if (ballRadius < maxRadius) {ballRadius*=1.05;}
                break;

            case KeyEvent.KEYCODE_Z:
                if (ballRadius > 20){ballRadius*=0.95;}
                break;
        }
        return true;
    }



    @Override
    protected void onDraw(Canvas canvas) {
        ballBounds.set (ballX-ballRadius, ballY-ballRadius, ballX+ballRadius, ballY+ballRadius);
        paint.setColor (Color.CYAN);
        canvas.drawOval (ballBounds, paint);

        update();

        try {
            Thread.sleep (30);
        }catch (InterruptedException e){}
        invalidate ();
    }

    private void update(){
        ballX+=ballSpeedX;
        ballY+=ballSpeedY;

        if(ballX+ballRadius > xMax){
            ballSpeedX = -ballSpeedX;
            ballX = xMax-ballRadius;
        }else if (ballX-ballRadius < xMin){
            ballSpeedX = -ballSpeedX;
            ballX = xMin+ballRadius;
        }

        if(ballY+ballRadius > yMax){
            ballSpeedY = -ballSpeedY;
            ballY = yMax-ballRadius;
        }else if (ballY-ballRadius < yMin){
            ballSpeedY = -ballSpeedY;
            ballY = yMin+ballRadius;
        }
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        xMax = w-1;
        yMax = h-1;
    }
    }


**AndroidOrientationSensor.java**:

    package com.example.maija.pomppupallo;


    import android.app.Activity;
    import android.hardware.SensorManager;
    import android.os.Bundle;
    import android.view.OrientationEventListener;
    import android.widget.TextView;
    import android.widget.Toast;

    public class AndroidOrientationSensor extends Activity{

    TextView textviewOrientation, tv1, tv2;
    OrientationEventListener myOrientationEventListener;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textviewOrientation = (TextView)findViewById(R.id.textorientation);
        tv1 = (TextView) findViewById (R.id.textorientation);
        tv2 = (TextView) findViewById (R.id.hellou);

        myOrientationEventListener
                = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){

            @Override
            public void onOrientationChanged(int arg0) {
                // TODO Auto-generated method stub
                textviewOrientation.setText("Orientation is: " + String.valueOf(arg0));
            }};

        if (myOrientationEventListener.canDetectOrientation()){
            Toast.makeText(this, "Can DetectOrientation", Toast.LENGTH_LONG).show();
            myOrientationEventListener.enable();
        }
        else{
            Toast.makeText(this, "Can't DetectOrientation", Toast.LENGTH_LONG).show();
            finish();
        }





    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        myOrientationEventListener.disable();
    }
}

Okay. I hope someone understands what the problem is here! Thank you in advance!

*Note: The Sensor-file isn't ready yet, there is some errors.*