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 have installed all the basic Android settings. We tried to run Android Sample projects in Eclipse. But for now, compiling the following lines and several other lines that use the "R" variable throws an error.

setContentView (R.layout.activity_main);

'R cannot be resolved to a variable'. I do not understand what causes the error. Someone help me on this.

+4
source share
10 answers

check that import for class R is not

import com.android.R; 

and you have to do it

 import yourpackagename.R; 

then recompile

+7
source

Try to clear the project and try compiling again.

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

+3
source

If you have a 64-bit Linux platform without ia32 libraries, this problem may also occur. It took me a while to relate this, seeing that the problem was clearly not due to the inability to execute 32-bit code.

+2
source

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

+1
source

In my case, I forgot to reinstall the SDK. When you reinstall your operating system, you must re-extract (reinstall) your ZIP SDK file.

+1
source

Also make sure that you have configured your Android libraries correctly in the Eclipse settings (if you use eclipse for development).

0
source

Make sure your resorption name (e.g. template.xml) has ONLY small letters.

0
source

import com.packagename.R * will worl

0
source

Change import to

 import yourpackagename.R; 

If the error still exists,

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

and delete the error line several times so that it gives an error in the files with the ability to draw.

0
source

setContentView (R.layout.activity_main)

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

0
source

Source: https://habr.com/ru/post/1381403/


All Articles