0

I am beginner using Android Studio and am following a tutorial on changing the screen background using the following code:

package com.example.gallcock.lighthead_app;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

    Button button_change;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void myButtonListen() {

        RelativeLayout bgElement = RelativeLayout)findViewById(R.id.activity_main);
    }



}

The activity_main in the last line shows red and the error msg when run, reads, 'Error:(23, 69) error: cannot find symbol variable activity_main'.

Could anyone help me out on this one? Thanks.

Here is the xml file below:

<?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.gallcock.lighthead_app.MainActivity">


<Button
    android:id="@+id/button_head"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Change"
    tools:layout_editor_absoluteX="148dp"
    tools:layout_editor_absoluteY="231dp" />



</android.support.constraint.ConstraintLayout>          
Greg
  • 1
  • 1

0 Answers0