-3

I am building an android app in eclipse, and I decided to rename the package of the app under "src", by right-clicking the package and choosing "Refactor" and then "Rename". I did the same for the package under "gen". I then renamed the package in the AndroidManifest.xml. However I now have a "R cannot be resolved to a variable" error. In my package under "gen" there is no R.java file, only a "BuildConfig.java".

I have tried cleaning the project and re-building after deleting the "gen" folder. I have no "import android.R" statements in any of my classes, and eclipse is saying there are no errors in my xml files. All of my xml and image files are named in all lowercase with no special characters. I have tried restarting eclipse a number of times.

How can I fix this problem and get R.java back to get my code working again? Thank you.

  • clean rebuild and restart eclipse.. should fix – Elltz Oct 17 '14 at 21:34
  • post your manifest and post your class imports and package just the top of your class.. guessing that error will be in manifest – Elltz Oct 17 '14 at 21:56
  • I actually just solved it myself! I had to re-add the android.support.v7.appcompat package to my "gen" folder, which must have gotten deleted, because my styles were dependant on it. Thank you! –  Oct 17 '14 at 22:02

1 Answers1

3

Usually this happens when there is an error in xml files Try Project->Clean in Eclipse. In my limited experience if R.java is not being automatically created then there is an error somewhere in your xml.

Ravin
  • 10,278
  • 1
  • 14
  • 20
  • Thanks, but like I said, I've tried cleaning it a number of times with no success. And as far as eclipse is telling me, there are no errors in my xml apart from "Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'" in res\values\styles.xml. –  Oct 17 '14 at 21:42
  • File->Import (android-sdk\extras\android\support\v7). Choose "appcompat" Project-> properties->Android. In the section library "Add" and choose "appCompat" That is all! – Ravin Oct 17 '14 at 22:05
  • Reference http://stackoverflow.com/questions/17870881/cant-find-theme-appcompat-light-for-new-android-actionbar-support – Ravin Oct 17 '14 at 22:05
  • Yes, that's what I found, thanks! I thought the styles errors were symptoms of the problem, rather than the cause, so to speak. –  Oct 17 '14 at 22:13