3

I had R.java file in my android application. But I don't know, It is delete some how. To create it again I clean my project and also Rebuild my project by clicking on Build Project. I do not know what is the problem. It is not getting created again. Generally It gets created automatically whenever I build project.

IT_INFOhUb
  • 516
  • 8
  • 21
  • 40

5 Answers5

2

If you are facing this problem after updating ADT, you should install that Android Build Tools . In my case installing Build Tools and restarting eclipse solved this problem.

adityag
  • 603
  • 3
  • 8
  • 24
1

Try this:

  1. Delete any import to an R.java class
  2. Move your cursor to a reference to any button/layout/string/whatever-coming-from-R, delete the last character, and hit ctrl+space. Eclipse will try to codehint you, automatically importing the correct R.java.
  3. clean and rebuild.
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • I have checked everything. But there not codehint is getting generated and I did many times clean project and Build Project. But R.java is not getting created. Everywhere in R.layout.smting / R.id.btn1 etc.. showing Error under "R". And R.java file is missing. – IT_INFOhUb Dec 27 '12 at 09:00
  • So, Clearly there is a problem in your xml file.double check it once, – Ram kiran Pachigolla Dec 27 '12 at 09:02
1

Some quick solutions to your problem might be,

  • use the Ctrl + Shift + O command to "Organize Imports" and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the R.java class that is automatically generated when you build.
  • R is a generated class. If you are using the Android Development Tools (ADT) it is generated whenever the project is built. You may have 'Build Automatically' turned off. Turn it on and build your project.
  • Mistakes in your xml views could cause the R.java not to be generated. Go through your view files and make sure all the xml is right!
  • Remove, if any import android.R;
  • Restart your IDE.
Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
  • Yeah I know it is automatically generated when we build. And my 'Build Automatically' is also turned on. I know about android.R import. It is not in my any activity class. I have checked my all imports. And I have restarted my IDE also. and I have check my layout xml files also. It is proper. – IT_INFOhUb Dec 27 '12 at 09:07
  • There might be something wrong with the xml's. check whether the names in the drawable or layout folder should not be in capital letters. – Sahil Mahajan Mj Dec 27 '12 at 09:09
  • Thank you I have found the my mistake. By mistake I put 2 images with same name but extension was img.jpg and another img.bmp so after deleting img.bmp problem have been solved. – IT_INFOhUb Dec 27 '12 at 09:27
1

You can create R.java file using aapt tool by executing following command.

ANDROID_HOME/platform-tools/aapt
                    package
                    -v
                    -f
                    -m
                    -S DEV_HOME/res
                    -J DEV_HOME/src
                    -M DEV_HOME/AndroidManifest.xml
                    -I ANDROID_HOME/platforms/android-7/android.jar

Generate Resource java code and packaged Resources

aapt  package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library} -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]

You can find more detail about options on this link

http://www.herongyang.com/Android/Project-aapt-Android-Asset-Packaging-Tool.html

Prateek
  • 12,014
  • 12
  • 60
  • 81
1

yeah,maybe there are some error in your layou or drawable dir. see the [problems tag] to get more detail

Tzig
  • 31
  • 3
  • 1
    Thank you I have found the my mistake. By mistake I put 2 images with same name but extension was img.jpg and another img.bmp so after deleting img.bmp problem have been solved. – IT_INFOhUb Dec 27 '12 at 09:25