1

i'm new to android, i'm getting this error. please help me in providing the solution

enter image description here

Thanks in advance.

Naruto
  • 9,476
  • 37
  • 118
  • 201

5 Answers5

3

R cannot be resolved to a variable When we will get this error.

R.java is an automatically generated file to hold all your resources used in project. It will be created under gen folder when you build your project. While building your project it will assign IDs to each resource you used in project and keeps them in their individual classes (drawable, id, layout, etc.) and creates a file R.java, place it in your package.

If anything wrong in your resource files (drawables or xml layouts) it won't generate R.java file.

So please check it once. I too faced same problem previously.

Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67
2

All the resources in Android are referenced by an 'id'. This 'id' is generated automatically in the file 'R.java', which itself is generated in automatically in 'gen' folder, once you build the project. So, what you have to do is just 'Build your Project'

Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
1

Build you project and you will get you.package.name.R.java file - and just import it.

Jin35
  • 8,602
  • 3
  • 32
  • 52
  • When i add, i get "The import You.are.hell.R cannot be resolved" error wat to do? – Naruto Dec 20 '11 at 04:53
  • You have some problems in xml or drawables - solve it first, than R file will be generated – Jin35 Dec 20 '11 at 04:58
  • You have only one xml file? What do you have in `res` folder except `layout/main.xml`? – Jin35 Dec 20 '11 at 05:07
  • Hi, i have these many files drawable-hdpi\ic_launcher.png drawable-ldpi\ic_launcher.png drawable-mdpi\ic_launcher.png layout\main.xml values\strings.xml – Naruto Dec 20 '11 at 05:12
  • So, you just create new "Hello, world" app? If so try to create new one - without proguard and with package name in low case. – Jin35 Dec 20 '11 at 05:18
  • One issue is solved, but another issue arisen "Description Resource Path Location Type Error generating final archive: java.io.FileNotFoundException: C:\eclipse-god\koko\bin\resources.ap_ does not exist unknown Android Packaging Problem " – Naruto Dec 20 '11 at 09:18
1

I think I saw the problem. You are having 2 folders named 'res'. Just delete the res folder which is empty and Clean, build the project

Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
1

if your gen folder is still missing then check whether you have done installation properly and then check if you have any error on any of the xml files in your project

refer following links

R cannot be resolved - Android error

No generated R.java file in my project

No generated R.java file in my project

http://www.joshuakerr.com/2009/10/23/android-and-the-missing-gen-folder/

Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95
  • I have done standalone installation , i have installed V2.1 platform and the eclipse version is Indigo.. is this error platform dependent ? – Naruto Dec 20 '11 at 05:48
  • Hey, setup seems fine. I reinstalled everything... i dont no what to do – Naruto Dec 20 '11 at 06:33
  • see this link [http://stackoverflow.com/questions/6482268/eclipse-indigo-cannot-install-android-adt-plugin] .Android works fine on eclipse galileo – Shruti Dec 20 '11 at 07:19
  • I tried on Helios, i installed fresh ADK, in tat i choose only android dev kit i.e 2nd option.. still giving same problem – Naruto Dec 20 '11 at 07:42
  • One issue is solved, but another issue arisen "Description Resource Path Location Type Error generating final archive: java.io.FileNotFoundException: C:\eclipse-god\koko\bin\resources.ap_ does not exist unknown Android Packaging Problem " – Naruto Dec 20 '11 at 09:17
  • i think u now need to set java path in your ide – Shruti Dec 21 '11 at 06:06
  • Thanks, issue is solved. it was totally related to installation. Eclipse acts crazy sometimes, i don't no why it is :( – Naruto Dec 21 '11 at 06:57
  • so to thanks atleast accept a answer which helped you to resolve your problem – Shruti Dec 21 '11 at 07:14