R.java disappears after project clean

前端 未结 30 2012
傲寒
傲寒 2020-11-30 05:37

After I added some .png files into my Project Workspace drawable folder I refreshed my drawable folders in Eclipse and the newly added files showed up. But when I tried to a

相关标签:
30条回答
  • 2020-11-30 06:14

    Another thing: never try to run an application with the texteditor opened with a xml file. That will create a wierd run configuration that can only be fixed by project clean-up and sometimes can make the xml file to vanish (happened to me twice already).

    0 讨论(0)
  • 2020-11-30 06:15

    Several things you should check in your project:

    • Check the Problems tab in your Eclipse IDE. Are you sure that you did not introduced building problems while making changes with drawables? To check that you need to check xml source of affected layout and see if something is marked red.

    • In File explorer go to the directory where your Android project is. Check that you have file default.properties (.classpath, .project and AndroidManifest.xml should be there). If default.properties is missing it may be easily replaced by correct version.

    • Which is the Android version you are working with? If that is 1.5 or lower be sure that in the res directory you have directory named drawable, not drawable-hdpi, drawable-mdpi and drawable-ldpi. Last three are valid for version 1.6 and higher.

    • Right click on your project in Package explorer in Eclipse. You will get a number of options. Go to Android Tools-> Fix Project Properties so see if that helps.

    0 讨论(0)
  • 2020-11-30 06:15

    Was there an XML file with the naming convention of "somthing.out.xml" generated? If so you should delete this file (an unwanted file of this name can cause major problems for your somthing.somthing.R file import).

    In some versions of eclipse (I know eclipse javaEE does this for sure), running the project while viewing an XML file will create a file called filename.out.xml in your res->layout folder. You must delete this generated file if this has occurred otherwise you wont be able to get the java.R file to import.

    0 讨论(0)
  • 2020-11-30 06:16

    Try Project->Clean in Eclipse. In my limited experience if R.java is not being automatically created then there is an error somewhere in your xml. Triple check everything.

    0 讨论(0)
  • 2020-11-30 06:16

    You have to build the project to be able to use the newly added resources.

    Cleaning a project removes all auto-generated files. Building the project it should automatically create them. When you Clean a project, there's an option to start a build immediately after clean up.

    Here's a few things you can try (did the same procedure after manually deleting the "gen" directory.

    • After you have deleted the gen directory, go to Project > Clean ...
    • You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
    • Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.

    Let me know if this works for you.

    0 讨论(0)
  • 2020-11-30 06:16

    Make sure your png files have lowercase names. That is what kept throwing mine out, because I capitalized the first letter, or I used an unallowed non alpha numeric in the naming. Check that before destroying any of your code.

    0 讨论(0)
提交回复
热议问题