Error: Cannot find symbol variable

I watched a tutorial from this guy:
https://www.youtube.com/watch?v=-SUvA1fXaKw

At the end (about 9:55) he wrote down:

if(fragment != null) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.content_main, fragment);
        ft.commit();

I renamed my content_main in activity_main_menu1_start_seite and I thought I could just replace the content_main with activity_main_menu1_start_seite, but then it says "cannot find Symbol variable activity_main_menu1_start_seite"

Maybe you Need my whole Code.
I marked you the error as the Blockquote.
Sorry for any issues (I am new to this site)

package com.d_and_d_studios.test3;
import android.Manifest;
import android.app.Fragment;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import at.markushi.ui.CircleButton;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

   CircleButton btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_drawer);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        btn = (CircleButton) findViewById(R.id.circleButton);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    //Brauche ich vielleicht doch noch irgendwann!
    //@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);
    //}

    private void displaySelectedScreen(int id) {
        Fragment fragment = null;

        switch (id) {
            case R.id.nav_powersavingmode:
                fragment = new Menu_2_Energiesparmodus();
                break;
            case R.id.nav_feedback:
                fragment = new Menu_3_Bewerte_die_App();
                break;
            case R.id.nav_send:
                fragment = new Menu_4_Teile_uns_Fehler_mit();

        }

if(fragment != null) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.activity_main_menu1_start_seite, fragment); ft.commit(); }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_powersavingmode) {
            // Handle the camera action
        } else if (id == R.id.nav_feedback) {

        } else if (id == R.id.nav_send) {

        }

        displaySelectedScreen(id);
        return true;
    }
}

<?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"
    android:background="@color/backgroundcolor"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.d_and_d_studios.test3.MainActivity"
    tools:showIn="@layout/toolbar_main">

    <at.markushi.ui.CircleButton
        android:id="@+id/circleButton"
        android:layout_width="116dp"
        android:layout_height="116dp"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_power_settings_new_black_24dp"
        app:cb_color="#000"
        app:cb_pressedRingWidth="20dp"

        tools:layout_editor_absoluteY="178dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/menu1_text1"
        android:fontFamily="sans-serif"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintVertical_bias="0.23" />

</android.support.constraint.ConstraintLayout>

2 answers

  • answered 2017-06-17 19:14 Code-Apprentice

    The R class is generated based on the names and content of files in the res subfolder of your project. If Android Studio does not do this automatically, you can force a manual build by clicking the Build button on the toolbar.

  • answered 2017-06-17 19:14 cricket_007

    Which xml contains an ID of activity_main_menu1_start_seite?

    Renaming the XML file only affects the R.layout values, and include tags in the other xml files.

    If it can't find R.id.activity_main_menu1_start_seite, then nothing contains android:id with that name. Specifically, you need a ViewGroup (such as a FrameLayout) within activity_main_drawer.xml with that value