Reputation: 241
I am making an alarm clock. In one of my java file I have to find an drawable file like this: layout.setBackgroundResource(R.drawable.view_touch_selector);
But, it shows error and says can't resolves symbol view_touch_selector. I don't know why it's happening although I have that corresponding view_touch_selector created.
UPDATE (after original android's answer):
Can't resolve symbol 'R' error! The 'R' becomes red in each file.
Upvotes: 0
Views: 2934
Reputation: 6215
I think the problem is that view_touch_selector has not been created in the generated R.java file. This is an anomaly (may be common) so you'll have to try one or more of the steps listed below (ordered from easiest/short time to longer). If you execute step 1, then do compile. Then try step 2, then compile, and so on. From Android Studio, using either File or Menu bar:
The idea is to make the Studio recompile your xml files correctly; Eclipse has a similar problem. Finally, if all else fails, rename your package, forcing all the project files to be evaluated. Warning, renaming package is not easy. I never had to do this for fixing this kind of problem.
EDIT: R.java file is at few places. The directories listed here is generated by Android Studio. R.java is at
- [project directory]\Application\build\generated\source\r\debug\com\example\android[package name]
There are intermediate files generated by compiler including view_touch_selector.xml:
- [project directory]\Application\build\intermediates\res\debug\drawable
Another file to check, though this is rarely a problem I think, is workspace.xml. When you select File -> Synch, workspace.xml is updated. File is at [project directory].idea. Again this is using Android Studio.
In workspace.xml, it should include your xml files like:
layout url="file://$PROJECT_DIR$/Application/src/main/res/layout/view_touch_selector.xml">
Between R.java and workspace.xml, they should be updated to the latest date/time. And if you don't see the R.java file, then that's a major problem related to directories. You may have to create a new project.
Good luck on this one, Tommy Kwee
Upvotes: 4