0

R cannot be resolved to a variable. So I tried to do "fix project setup", but then it can't identify all of its subcontent, such as objects from my xml, R.id.X, R.drawable.Y, none of them are identified.

I just tried to follow http://developer.android.com/guide/topics/ui/controls/pickers.html guide and add such class to have a dialog for choosing time.

    Description Resource    Path    Location    Type
users cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 170    Java Problem
ic_launcher cannot be resolved or is not a field    MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 159    Java Problem
about cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 136    Java Problem
menu_user cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 133    Java Problem
imp_logo cannot be resolved or is not a field   MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 198    Java Problem
activity_main cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 44 Java Problem
timerCB cannot be resolved or is not a field    MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 64 Java Problem
timerTime cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 65 Java Problem
statusText cannot be resolved or is not a field MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 66 Java Problem
timerText cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 67 Java Problem
start_button cannot be resolved or is not a field   MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 68 Java Problem
stop_button cannot be resolved or is not a field    MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 69 Java Problem
activity_main cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 123    Java Problem
menu_url cannot be resolved or is not a field   MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 130    Java Problem
Puck
  • 2,080
  • 4
  • 19
  • 30
buddy123
  • 5,679
  • 10
  • 47
  • 73
  • Project->Clean... If you don't have build automatically, then build it too. Another possibly is there's a compilation error in your resources and the project won't build until that's resolved. – DeeV Feb 22 '13 at 14:17
  • post your code and log... – nano_nano Feb 22 '13 at 14:17
  • This could be a problem within your XML, try to find the root cause.. but first try the simple solution of cleaning your project, – JoxTraex Feb 22 '13 at 14:18
  • if you got an error in Your code or xml layouts, then eclipse won´t rebuild R.java. Check for some error, if You found one, correct it and clean your project – Opiatefuchs Feb 22 '13 at 14:19
  • another thing to check is if any of the recently add resources are incorrect, i.e. double check your xml if you added any, and ensure only lowercase names on drawables etc... Sometimes R will fail to generate because you've broken either an xml or drawable resource. – FoamyGuy Feb 22 '13 at 14:19
  • I havent change anything in the xmls,and reverted everything back anyway. i get these errors i addded to main post – buddy123 Feb 22 '13 at 14:26

4 Answers4

2

Do Project -> Clean for a few times.

And then Build the project.

If you still cant find R.java in the gen folder, check if you have ANY errors in your layout files, for example check if all your xml files and drawables are named only in lower-case letters.

After removing these errors, Clean and Build once again.

Swayam
  • 16,294
  • 14
  • 64
  • 102
  • Oh, well.. Great! :D It does take a little bit of time to get your hands settled with Android development and Eclipse. Anyway, good luck ahead! – Swayam Feb 22 '13 at 15:21
2

Simply remove import android.R and it will work.

Saro Taşciyan
  • 5,210
  • 5
  • 31
  • 50
Mobeen
  • 259
  • 1
  • 8
1
  • clean the project by selecting Project - Clean
  • if R.java is not created, delete the gen folder, then re-create it manually, right-click, Build Path - use as source folder, rebuild the project
  • if R.java is still not there, there is a probability that some of your XML files contain errors, check that
  • in case your project's origin is an svn repository, there might be some invisible config files which the compiler does not recognize. Right-click your project - Properties - Resources - Resource filters - add- exlude all - files and folders - name matches .svn
  • in case you downloaded and imported your project, check the target (SDK) and mare sure you have the required packages installed.
Droidman
  • 11,485
  • 17
  • 93
  • 141
1

The above answer states it clearly. Take a look at your layout files and a hint from me: When I filled by strings.xml file, I found out, that when copying some colors there, I closed the tag with a tag. This is easily overlooked thing and i intend of writing a class which detects this, because apparently this isn't going to be fixed anytime soon (by fixed I mean at least a notification for us).

g00dy
  • 6,752
  • 2
  • 30
  • 43
  • suddendly it disappeared. I have no clue what happened. really. the clean didnt help and i didnt change/had to save any edited files. – buddy123 Feb 22 '13 at 14:31
  • Yes, it will help you only if you corrected your error. For example, if you made a mistake in a layout and you did clean-up - the R.java will dissapear. But after that you unconsciously corrected the error. This is the main reason for the R.java to dissapear, believe me. It's recommended after soem modifications to do a clean-up and/or build, to see if something somewhere went wrong, otherwize after some 300-400 lines of code it will be unfindable. – g00dy Feb 22 '13 at 14:58