R is unresolved


#1

I create a new project in Android Studio and when I create a new activity for my project the IDE display me an error says this:

unresolved Reference: R

This error appear in both files in onCreate() method

setContentView(R.layout.activity_main)

I tried build, clean and rebuild the project and nothing resolve this issue.

Someone have any idea how to solve this?

Thanks.


#2

Did you import R? The IDE can help import it. Just invoke one of the quick fix intentions, then import the R from your project.


#3

Hi @fatjoe79, my project import this:

import code.diegohdez.github_api.R

where R is marked with red where says: Unresolved reference: R

setContentView(R.layout.activity_get_token)

also display the same error: Unresolved reference: R

I don’t know what happen.


#4

I assume this worked before, right?

The root cause for this problem is often an error in one of your resource files (layout resource, etc). Check the output of the gradle build.


#5

Click on Build->Clean Project and that will perform a gradle clean


#6

R is a static class R. it created when you create resource and build it. It have all resource ID as Static for you application access all resource in your activity. This error mean you unsuccessfully build resource , please check all your resource have something Error, so R class static not created successful.