1

I am building an application and I added a new activity to generate a view. I compiled it. My application can not find anything that is on the format R.id.xxx or R.layout.xxx, I've tried also cleaning my project, closing Eclipse and opening Eclipse again, but nothing. The most strange thing is that before everything was working well. But now it can not recognize even the R.layout.main that is default of my principal activity. Anyone have an idea?

Also I have tried almost everything here: R cannot be resolved - Android error but no result!

Solved

Thanks to woopsy, also I found the reference to this kind of problem

http://source.android.com/source/using-eclipse.html

it happens because Eclipse sometimes imports R when you press the combination ctrl+shift+O

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
Pedro Teran
  • 1,200
  • 3
  • 17
  • 43

8 Answers8

4

Remove all your imports for the Activity and then have eclipse fix imports. I have had problems where eclipse wants to import a different R than the one I need.

Woodsy
  • 3,177
  • 2
  • 26
  • 50
  • 1
    it happens when you copy paste code of some other project, eclipse fix imports it with the R.java file of the source project. – noob Feb 23 '12 at 21:29
2

First of All Check You have R.java File then check

import android.R; 

Enter Yourpackages like import com.mypackages.prj;

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
0

this is a common error. You need to just search your R.java file in generated section of your project directory in Eclipse. Need to import if the R.java file into the package then import . R; I hope it will work for you. It was absolutely worked for me...enjoy programming

0

friends take care that u haven't imported R class, if you have delete "import android.R". The reason is there are two R things one R.java and R.class and we need the java, where we dont need to import rather than referring it. It worked for me and may be to you too.

0

I found the solution...For me works it

Poject->Properties->Android->Project Build Target (here choose android4.4 or 5.1.1 Android Open Source Project)->Ok Project->Build All

This function ...

0

This problem can fix with this process: - File---->Invalidate cache/restart.

it will restart your android studio and fix that problem

0

If you are using eclipse, take a backup of your layout main.xml file and then from the eclipse new file interface create a new "Android XML File" and call it main.xml. copy back from the backup the contents into this new file.

try this.

Sid
  • 7,511
  • 2
  • 28
  • 41
0

check your xml files. there might be something wrong in it which is causing R not to build up automatically. To observe such errors, switch your view to Console tab

waqaslam
  • 67,549
  • 16
  • 165
  • 178