1

I add a new menu res(add.xml) to my android project and I am getting Cannot resolve symbol R in the all my java file

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_save"
        android:title="@string/action_save"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_discard"
        android:title="@string/action_discard"
        app:showAsAction="never" />
</menu>

I have tried Build > Clean project and Tools > Android > Sync Project with Grade Files but none work

  • 1
    http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error – assylias Mar 15 '16 at 19:11
  • Sometimes simply restarting your Android Studio and rebuilding gradle will fix the problem. Try it, nothing you can lose. Weird bug, happened to me a couple of times... :/ – Vucko Mar 15 '16 at 20:19

2 Answers2

0

Check for the /res directory. Usually this is caused by a problem in your XML files, or some missing resource. Also, check at the top of your file, maybe there is this line:

import android.R

this can happen when the IDE auto-generate your imports.

Stolous
  • 19
  • 5
0

Thanks to everyone. I have been able to solve the problem by renaming the xml file from add.xml to another name. I guess the name add.xml is conflict with another internal file name