No generated R.java file in my project

120,743

Solution 1

Go to Project and hit Clean. This should, among others, regenerate your R.java file.

Also get rid of any import android.R.* statements and then do the clean up I mentioned.

Apparently Jonas problem was related to incorrect target build settings. His target build was set to Android 2.1 (SDK v7) where his layout XML used Android 2.2 (SDK v8) elements (layout parameter match_parent), due to this there was no way for Eclipse to correctly generate the R.java file which caused all the problems.

Solution 2

After one whole day trying to find why R file was not generated, I found that after install Android SDK Tools r22 a new option in Tools was available: Android SDK Build Tools.

After installing it R file was generated again.

Solution 3

now you have imported android.R instead of your own R... Try to take a look on your "problems" view if you have errors in one of your xml files... get rid of the import android.R and comment out all usages of R.*

Cleaning should help when your project has no other errors, so check your xml files or file naming in your res folders

Solution 4

Probably u might be using a incorrect SDK version. Right click on your project. Select Properties-->Android. Note that 2.2 is the latest SDK. Check it and see if it gets compiled...

Edit

Also Do a clean after that

Solution 5

I Had a similar problem

Best way to Identify this problem is to identify Lint warnings:: *Right Click on project > Android Tools > Run Lint : Common Errors*

  • That helps us to show some errors through which we can fix things which make R.java regenerated once again
  • By following above steps i identified that i had added some image files that i have not used -> I removed them -> That fixed the problem !

Finally Clean the project !

Share:
120,743
Jonas
Author by

Jonas

Passionated Software Developer interested in Distributed Systems

Updated on July 09, 2022

Comments

  • Jonas
    Jonas almost 2 years

    I am doing the Notepad tutorial, exercise 2. I started by creating a new Android project and chose Create from source to import the downloaded source files for the excercise.

    But now I get many errors in Eclipse, and the problem is that there is no generated R.java class. How can I solve this? The folder gen/ is empty.


    I have errors on Notepadv2.java and in res/layout/note_edit.xml and both seems to be related to the fact that the generated R.java is missing.

    Here is my import statements in Notepadv2.java:

    import android.R;
    import android.app.ListActivity;
    import android.content.Intent;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.view.ContextMenu;
    import android.view.ContextMenu.ContextMenuInfo;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.ListView;
    import android.widget.SimpleCursorAdapter; 
    

    They are created by the Eclipse command Ctrl+Shift+O.

  • Octavian Damiean
    Octavian Damiean over 13 years
    @Jonas: Please post up your imports.
  • Jonas
    Jonas over 13 years
    The project target is set, but I don't know about "min sdk level". Where can I see if it is set? In default.properties I only have target=android-7
  • Octavian Damiean
    Octavian Damiean over 13 years
    @Jonas: this means that the target build is set to Android 2.1.
  • Octavian Damiean
    Octavian Damiean over 13 years
    @Jonas: exactly. The import section of your main application.
  • srinathhs
    srinathhs over 13 years
    There is also an attribute in manifest <uses-sdk android:minSdkVersion="8" />. Did you see any kind of "errors" in the problems tab or Console?
  • Jonas
    Jonas over 13 years
    When I change build target from Android 2.1 to Android 2.2 the R.java is generated. But when I change back to Android 2.1 and after I do Project>Clean then the R.java is deleted again.
  • Octavian Damiean
    Octavian Damiean over 13 years
    @Jonas: Don't change the target build. Have you tried what I've mentioned?
  • Jonas
    Jonas over 13 years
    When I remove import android.R I have two errors in the Problems view. They are R cannot be resolved to a variable in Notepadv2.java and error: Error: String types not allowed (at 'layout_height' with value 'match_parent') in note_edit.xml
  • Jonas
    Jonas over 13 years
    Yes, see my comment to WarrenFaith
  • Jonas
    Jonas over 13 years
    Yes, Project > Clean doesn't help me. After that I get two errors in the Problems view. See my comment to WarrenFaith
  • Octavian Damiean
    Octavian Damiean over 13 years
    Well if your target build is 2.1 then match_parent won't be available since it was added in Android 2.2.
  • Jonas
    Jonas over 13 years
    In Properties > Android I can only choose a Build target and it is Android 2.1 which I want. There is also an empty Library section in the same dialog.
  • Jonas
    Jonas over 13 years
    @Octavian: Ah, so the XML failed to parse, so no R.java is generated. Now when I change build target to Android 2.2 it seem to work. You could add that to your answer.
  • DeRagan
    DeRagan over 13 years
    Yes in build target you should have selected 2.2 and yes you were indeed using the incorrect SDK version :)
  • ina
    ina almost 13 years
    after wading through legions of google groups mess trying to find this solution... what'd you know, it was on SO the whole time.
  • Saher Ahwal
    Saher Ahwal almost 13 years
    why getting rid of the import solves the issue? That doesn't make sense to me?
  • Octavian Damiean
    Octavian Damiean almost 13 years
    @Saher Because having the R file of another package in your class will definitely screw up everything.
  • m2web
    m2web almost 12 years
    This was close to the problem I was having--I think somehow I was missing something in the buildSpec section of my .project file. Not sure how it got that way, or the correct way to fix it, but I basically copy/pasted from a working project and got R.java building again.
  • ademers
    ademers about 11 years
    That did the trick. Thank you.
  • Larry McKenzie
    Larry McKenzie about 11 years
    I am looking for this new option where can I find it?
  • amar
    amar about 11 years
    Right Click on project > Android Tools > Run Lint : Common Errors
  • Arnaldo Ignacio Gaspar Véjar
    Arnaldo Ignacio Gaspar Véjar about 11 years
    Finally i solve this problem updating the Android SDK Tools and restarting eclipse, very thanks
  • marzapower
    marzapower about 11 years
    Thank you! Why do they always have to break things???
  • Linson
    Linson about 11 years
    Thats really worked, Thank you very much.
  • Ankit
    Ankit about 11 years
    Thanks.. That worked, you saved my day.
  • Jay Snayder
    Jay Snayder about 11 years
    Yep, same here. Another thanks. I thought that I had already gone through that process, but it must have gotten interrupted in between when I was closing eclipse during the download and it never finished.
  • Vivek Warde
    Vivek Warde over 10 years
    If this cannot solve this issue then other answers can be considered !
  • sjngm
    sjngm over 10 years
    I don't know if it's a new feature, but my layout files have an underscore in their name and everything works fine.
  • avasal
    avasal almost 10 years
    +1 this works, but make sure there is no other error in the project