0

I am new to android programming and recently developed a weird error in my code. I was following a tutorial that directed the coder to go to project>clean (in eclipse). After I clicked it my code developed errors whenever I tried to access a resource. I received an error on the R. It said that the variable R cannot be recognized. Eclipse recommends that I import the package "R" which did not work. An example of the line of code that had the error on is:

setContentView(R.layout.activity_main);

After I imported "R" eclipse was unable to recognize/find activity_main.

Mark J. Bobak
  • 13,720
  • 6
  • 39
  • 67
  • That means one of two things- either you have a compilation error in your resources, or you need to do a clean build in Eclipse. – Gabe Sechan May 16 '14 at 03:40
  • Go through this link [import android.R in Eclipse : Why?][1] [1]: http://stackoverflow.com/questions/15309941/import-android-r-in-eclipse-why – Aniruddha May 16 '14 at 03:44
  • I think there is problem in your project resource part it may xml,drawable or string due to this problem your R class not generated try to find it and resolved after your R class automatically generated. – Haresh Chhelana May 16 '14 at 04:22
  • Check the console pane in eclipse. It sometimes has more information about errors in the XML resource files. – Squonk May 16 '14 at 04:57

1 Answers1

1

You can check some steps.

1. resource activity_main layout or others resource ok or not.
2. your activity in above delete import Android.R
3. add your package_name.R for example. if your package name is com.example.helloworld, then import com.example.helloworld.R
4.delete bin folder and gen folder of your project.
5. clean your project , project=>clean.
and 6. finally restart your eclipse.

When any resource mismatch then this type error show.

Best of luck

kablu
  • 629
  • 1
  • 7
  • 26
  • 1
    Your step 3 is only necessary if there is more than one package. If there is only one package then you never need to import your own R.java class. – Squonk May 16 '14 at 04:55