0

I am having the same problem as some others have had on SO. In my project android studio says that it cannot resolve symbol R.

The weird thing is that it builds fine. My problem is similar to this post on SO.

The only thing that was mentioned in his answer is that this problem can occur when collaborating with others and i have had to download a master copy of project from GitHub because of errors.

I have tried the following with my project:

Cleaning project Rebuilding project. Renaming all files with spelling mistakes (helloworld to hello_world) Changing the project name from MyApp-Master to the original name MyApp. Running android lint to find any errors in the syntax of the code and fixing them Using values instead of hard coded attributes

I have also combed through the SO posts here and here but the suggestions where not helpful unfortunately.

I am using android studio 3.2.1

I have not included all classes where R is not resolved because it is in all of them. But here is the MainActivity.class

   package com.example.cohen.theepiccalculator;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {


     private DrawerLayout drawerLayout;
     private int drawerId;


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

        Toolbar toolbar = findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        if (actionBar != null) {
            actionBar.setHomeAsUpIndicator(R.drawable.ic_button_drop_down);
        }


        drawerLayout = findViewById(R.id.drawer_layout);


        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                drawerId = menuItem.getItemId();
                menuItem.setChecked(true);
                selectItem(drawerId);
                drawerLayout.closeDrawers();
                return true;
            }
        });


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                drawerLayout.openDrawer(GravityCompat.START);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void selectItem(int position){


        switch (position){
            case R.id.nav_currency :
                Intent intentC = new Intent(MainActivity.this, InputActivityCurrency.class);
                startActivity(intentC);
                Toast.makeText(MainActivity.this,"Currency", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_length :
                Intent intentL = new Intent(MainActivity.this, InputActivityLength.class);
                startActivity(intentL);
                Toast.makeText(MainActivity.this,"Length", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_weight :
                Intent intentW = new Intent(MainActivity.this, InputActivityWeight.class);
                startActivity(intentW);
                Toast.makeText(MainActivity.this,"Weight", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_temp :
                Intent intentT = new Intent(MainActivity.this, InputActivityTemperature.class);
                startActivity(intentT);
                Toast.makeText(MainActivity.this,"Temp", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_area :
                Intent intentA = new Intent(MainActivity.this, InputActivityArea.class);
                startActivity(intentA);
                Toast.makeText(MainActivity.this,"Area", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_speed :
                Intent intentS = new Intent(MainActivity.this, InputActivitySpeed.class);
                startActivity(intentS);
                Toast.makeText(MainActivity.this,"Speed", Toast.LENGTH_SHORT).show();
                break;
            case R.id.nav_vol :
                Intent intentV = new Intent(MainActivity.this, InputActivityVolume.class);
                startActivity(intentV);
                Toast.makeText(MainActivity.this,"Vol", Toast.LENGTH_SHORT).show();
                break;

        }


    }
}

And here is the related activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bluetwo"
    android:fitsSystemWindows="true"
    android:id="@+id/drawer_layout">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <include

            android:id="@+id/tbar"
            layout="@layout/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">


        <Button
            android:id="@+id/equels"
            android:layout_width="101dp"
            android:layout_height="183dp"
            android:layout_alignBottom="@id/point"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/ic_button_equals_orange" />

        <Button
            android:id="@+id/eight"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_toRightOf="@id/seven"
            android:layout_toEndOf="@id/seven"
            android:layout_alignBottom="@id/seven"
            android:background="@drawable/ic_button_eight_blue"
            android:layout_marginLeft="1dp"
            android:layout_marginStart="1dp" />

        <Button
            android:id="@+id/nine"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignBottom="@id/eight"
            android:layout_marginStart="1dp"
            android:layout_toEndOf="@id/eight"
            android:layout_toRightOf="@id/eight"
            android:background="@drawable/ic_button_nine_blue"
            android:layout_marginLeft="1dp" />

        <Button
            android:id="@+id/times"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_toEndOf="@id/persent"
            android:layout_toRightOf="@id/persent"
            android:layout_alignBottom="@id/persent"
            android:layout_marginLeft="1dp"
            android:background="@drawable/ic_button_times_blue"
            android:layout_marginStart="1dp" />

        <Button
            android:id="@+id/devide"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_toRightOf="@id/times"
            android:layout_toEndOf="@id/times"
            android:layout_alignBottom="@id/times"
            android:layout_marginLeft="1dp"
            android:layout_marginStart="1dp"
            android:background="@drawable/ic_button_devide_blue"
             />

        <TextView
            android:id="@+id/ValueTextBox"
            android:layout_width="422dp"
            android:layout_height="145dp"
            android:layout_alignBottom="@id/back"
            android:layout_marginBottom="90dp"
            android:background="@color/bluesemi"
            android:gravity="center_horizontal|center|end"
            android:padding="6dp"
            android:textSize="50sp"
            app:fontFamily="@font/zonaprothin"
            android:textColor="@color/bluetwo"/>

        <Button
            android:id="@+id/back"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignBottom="@id/seven"
            android:layout_marginBottom="92dp"
            android:background="@drawable/ic_button_back_space_blue"/>

        <Button
            android:id="@+id/persent"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_toEndOf="@id/back"
            android:layout_toRightOf="@id/back"
            android:layout_alignBottom="@id/back"
            android:layout_marginLeft="1dp"
            android:layout_marginStart="1dp"
            android:background="@drawable/ic_button_persentage_blue"
             />

        <Button
            android:id="@+id/four"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignBottom="@+id/one"
            android:layout_marginBottom="92dp"
            android:background="@drawable/ic_button_four_blue" />

        <Button
            android:id="@+id/five"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignStart="@+id/four"
            android:layout_alignLeft="@+id/four"
            android:layout_alignBottom="@id/four"
            android:layout_marginStart="103.5dp"
            android:layout_marginLeft="103.5dp"
            android:layout_marginBottom="0dp"
            android:background="@drawable/ic_button_five_blue" />

        <Button
            android:id="@+id/six"
            android:layout_alignBottom="@id/five"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_marginLeft="207dp"
            android:layout_marginStart="207dp"
            android:background="@drawable/ic_button_six_blue"/>

        <Button
            android:id="@+id/one"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignTop="@id/zero"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="-92dp"
            android:background="@drawable/ic_button_one_blue" />

        <Button
            android:id="@+id/two"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignBottom="@id/one"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_toEndOf="@id/one"
            android:layout_toRightOf="@id/one"
            android:background="@drawable/ic_button_two_blue" />

        <Button
            android:id="@+id/three"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_toEndOf="@id/two"
            android:layout_toRightOf="@id/two"
            android:layout_alignBottom="@id/two"
            android:layout_marginLeft="1dp"
            android:layout_marginStart="1dp"
            android:background="@drawable/ic_button_three_blue"
             />

        <Button
            android:id="@+id/plus"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_above="@+id/equels"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_toEndOf="@id/six"
            android:layout_toRightOf="@id/six"
            android:layout_alignBottom="@+id/six"
            android:background="@drawable/ic_button_plus_blue" />

        <Button
            android:id="@+id/minus"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_toEndOf="@id/nine"
            android:layout_toRightOf="@id/nine"
            android:layout_alignBottom="@id/nine"
            android:layout_marginLeft="1dp"
            android:layout_marginStart="1dp"
            android:background="@drawable/ic_button_minus_blue" />

        <Button
            android:id="@+id/seven"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_alignBottom="@id/four"
            android:layout_marginBottom="92dp"
            android:background="@drawable/ic_button_seven_blue" />

        <Button
            android:id="@+id/point"
            android:layout_width="102dp"
            android:layout_height="91dp"
            android:layout_above="@+id/zero"
            android:layout_alignBottom="@id/zero"
            android:layout_toEndOf="@id/zero"
            android:layout_toRightOf="@id/zero" />

        <Button
            android:id="@+id/zero"
            android:layout_width="205dp"
            android:layout_height="91dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentBottom="true"
            android:layout_marginStart="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginEnd="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginBottom="0dp"
            android:background="@drawable/ic_button_zero_blue" />

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/draw_items" />


</android.support.v4.widget.DrawerLayout>

If there is anything i have left out that might be helpful please let me know.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

when R fails, usually the error is in the xml or possibly not find a resource such as menu, images etc. You can do a build> rebuild project and attach the error.

good luck