0

Hey i am new to Android Development . I have added an image in the 'drawable' folder and the suddenly all the 'R' of the MainActivity.java becomes red stating

Cannot resolve symbol 'R'.

I have tried :-

  1. Closing the Project, closing AS and relaunching / reopening
  2. File > Invalidate Caches / Restart
  3. Rebuilding the project

But no luck , Can anyone please help me out and also tell me the reason of the error. Thanks .

Abhay Kumar
  • 5,048
  • 2
  • 16
  • 21

3 Answers3

2

Most likely, there is a problem with the drawable that you added, and that is blocking the R class from being code-generated. When you rebuild the project, the Gradle Console should show you the build errors that are causing the problem.

In particular, make sure that your drawable has a valid filename, consisting only of lowercase letters, numbers, and the underscore character.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

make sure all files in the res folder's subfolders have names that are ok : only lowercase letters, digits and underscore ("_") .

For exmaple:

 my-wall // this is wrong.

 my_wall // this is right

and make sure you don't import .R library.

If this does not work then follow the following links:

Community
  • 1
  • 1
Setu Kumar Basak
  • 11,460
  • 9
  • 53
  • 85
0

Check if there is any error when you try to build the project (go to view menu, then Tool Windows and then select Gradle Console). If no errors there, then try clean build once (go to Build menu and then clean project). Also, make sure the file name of the image you added is in lower case and no space in between.

Rakesh
  • 1,374
  • 1
  • 16
  • 24