“R cannot be resolved to a variable”? [duplicate]

2018-12-31 05:48发布

This question already has an answer here:

In Eclipse, I've created a project from a source and now it shows errors - "R cannot be resolved to a variable". From what I found here, I had cleared and rebuilt the project, but still the R file doesn't appear in the /gen folder.

Any ideas?

30条回答
还给你的自由
2楼-- · 2018-12-31 06:42

Dont worry. First you may clean the project, then run the project. If this does not work then follow the following links:

查看更多
忆尘夕之涩
3楼-- · 2018-12-31 06:42

Remove any XML files in the /res/menu folder.

查看更多
回忆,回不去的记忆
4楼-- · 2018-12-31 06:42

I been having this and i did trace it back to the layout files.. It happend to me again however i could not find noting in the layout files. I looked in the string.xml and there was it.. one of the string names started with cap and that was causing the problem.

查看更多
与风俱净
5楼-- · 2018-12-31 06:44

In my case, R.java wasn't getting generated because of a hierarchical parent error, which in turn was cured by updated one or more Eclipse plugins (Go Eclipse-->Help-->Check for Updates)

查看更多
孤独总比滥情好
6楼-- · 2018-12-31 06:47

for me, the best solution to suggest to people that have problems with the "R" file would be to try the next steps (order doesn't matter) :

  1. update ADT & SDK , Eclipse and Java.

  2. remove gen folder , and create it again .

  3. do a clean-project.

  4. right click the project and choose android-tools -> fix-project-properties .

  5. right click the project and choose properties -> java-build-path -> order-and-export. make sure the order is :

    • Android 4.3 (always the latest version)

    • Android private libraries

    • android dependencies

    • your library project/s if needed

    • yourAppProject/gen

    • yourAppProject/src

  6. make sure all files in the res folder's subfolders have names that are ok : only lowercase letters, digits and underscore ("_") .

  7. always make sure the targetSdk is pointed to the latest API (currently 18) , and set it in the project.properties file

查看更多
妖精总统
7楼-- · 2018-12-31 06:47

This can happen when the android naming convention isn't followed. Check if you have placed a file/photo into one of the android folders and make sure that the file name contains only lower case letters

查看更多
登录 后发表回答