Why Java file doesn't find the Drawable xml file in android studio? -


i making alarm clock. in 1 of java file have find drawable file this: layout.setbackgroundresource(r.drawable.view_touch_selector); but, shows error , says can't resolves symbol view_touch_selector. don't know why it's happening although have corresponding view_touch_selector created.

enter image description here

update (after original android's answer):

can't resolve symbol 'r' error! 'r' becomes red in each file.

enter image description here

i think problem view_touch_selector has not been created in generated r.java file. anomaly (may common) you'll have try 1 or more of steps listed below (ordered easiest/short time longer). if execute step 1, compile. try step 2, compile, , on. android studio, using either file or menu bar:

  1. select res/drawable folder project tree , select file -> synchronize.
  2. menu -> build -> rebuild project
  3. menu -> build -> clean project, build it.
  4. file -> invalidate caches / restart
  5. menu tools -> android -> sync project gradle files

the idea make studio recompile xml files correctly; eclipse has similar problem. finally, if else fails, rename package, forcing project files evaluated. warning, renaming package not easy. never had fixing kind of problem.

edit: r.java file @ few places. directories listed here generated android studio. r.java @

  • [project directory]\application\build\generated\source\r\debug\com\example\android[package name]

there intermediate files generated compiler including view_touch_selector.xml:

  • [project directory]\application\build\intermediates\res\debug\drawable

another file check, though problem think, workspace.xml. when select file -> synch, workspace.xml updated. file @ [project directory].idea. again using android studio.

in workspace.xml, should include xml files like:

layout url="file://$project_dir$/application/src/main/res/layout/view_touch_selector.xml">

between r.java , workspace.xml, should updated latest date/time. , if don't see r.java file, that's major problem related directories. may have create new project.

good luck on one, tommy kwee


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -