Unable to resolve R


This tripped me up for a while…

If you edit the strings.xml file to be as shown in listing 33.2 you will be removing a few string resources used by some of the default files. This will prevent you from compiling R.java and you will have issues using any of your resources. You will see errors such as ‘R cannot be resolved’

Files I noted that use a few of the default strings were layout/activity_run.xml and menu/run.xml

The solution is to either leave the extra strings in strings.xml or change these files to point to something like strings/app_name or another string that actually appears in the strings file.


thanks for posting that. I was stuck for a while wondering why the layout file was not being resolved. I had to add in the action_settings string in strings.xml and delete the hello world reference in the textview in the blank activity created at the start. after saving all things turned from red to blue :slight_smile:


Yep, I got tripped up by this too and a couple of extra points.

When setting up a new project in Eclipse, it automatically adds a res/menu/menu.xml (name may vary!) menu file which has a reference to an “@string/action_settings” string which will cause errors as the listing in 33.2 omits an action_settings string.

This can either be resolved by deleting the menu.xml file or adding a dummy actions_settings string in your strings.xml file.

It took me quite a while to resolve this as I spent ages comparing my code with that found in the downloaded solutions file and I think I may have found a further error in the solutions file as it does not contain a res/layout/activity_fragment.xml file. A need for this is mentioned in the book (P 526) but it doesn’t seem to appear in the source code.

And while we’re at it…

I notice that the source code AndroidManifest specifies a min SDK of 8 which doesn’t tie in with P 525 33.1 or Para 3 on P 529 which both say min SDK of 9.

Good book by the way. I’m a Brit too and understood the Flash analogy and enjoy the humour. In addition, you deserve 10 out of 10 for your engagement with these forums which shouldn’t be taken for granted. A previous Wrox Android book I’d read only had one post by the author in response to volumes posted by his readership. :slight_smile: