buddy123
buddy123

Reputation: 6317

Android project suddenly ruined, can't find R object

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

Upvotes: 0

Views: 2762

Answers (4)

Mobeen
Mobeen

Reputation: 269

Simply remove import android.R and it will work.

Upvotes: 2

Droidman
Droidman

Reputation: 11608

  • 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.

Upvotes: 1

g00dy
g00dy

Reputation: 6778

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).

Upvotes: 1

Swayam
Swayam

Reputation: 16364

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.

Upvotes: 2

Related Questions