Manoj Kumar
Manoj Kumar

Reputation: 135

Android Dev - R.layout.main , Variable 'R' cannot be resolved

We are new to Android and we are trying to develop a new application. We installed all the basic setup of Android. We tried to run the Android Sample projects in Eclipse. But while to compile the following lines and a few other lines that uses the variable 'R' throws up an error.

setContentView(R.layout.activity_main);

'R cannot be resolved to a variable'. I do not understand what is causing the error. Anyone help me out in this issue.

Upvotes: 4

Views: 39468

Answers (10)

SivaRamaKrishnan T
SivaRamaKrishnan T

Reputation: 31

setContentView(R.layout.activity_main)

Change the SDK and delete the project and create new ... it will definitely work!

Upvotes: 0

Umer
Umer

Reputation: 1556

Change import to

import yourpackagename.R;

If error is still there then

go to gen folder->packagename->R.java 

and remove error line some times it gave error on drawable files.

Upvotes: 0

user2544121
user2544121

Reputation:

In my case i forgot to re-install the SDK. When you re-install your operating system, you should re-extract (re-install) your SDK Zip file.

Upvotes: 1

Dapper Dan
Dapper Dan

Reputation: 1062

import com.packagename.R* will worl

Upvotes: 0

NTwoO
NTwoO

Reputation: 75

If you have 64 bit Linux platform without ia32 libraries, then this problem could also occur. It took me quite some time to pin this one down, seeing that the problem is not clearly linked with the inability to execute 32 bit code.

Upvotes: 2

Emre
Emre

Reputation: 1

Just make the import part import com.android.R.layout instead of com.android.R

Upvotes: 1

baron_bartek
baron_bartek

Reputation: 1127

Check if your resorce name (for example template.xml) has ONLY small caps letters.

Upvotes: 0

Bryan
Bryan

Reputation: 3667

Also check that you have your android libraries mapped correctly in the settings for Eclipse (if you are using eclipse to develop).

Upvotes: 0

confucius
confucius

Reputation: 13327

check that the import for R class is not

import com.android.R;

and you should make it

import yourpackagename.R;

then recompile

Upvotes: 7

Jason Kuang
Jason Kuang

Reputation: 261

Please try to clean the project, and try compiling again.

If not solved, refer to R cannot be resolved - Android error

Upvotes: 3

Related Questions