“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:35

I got similar problem and solution I found out was in resources any of the file aka background, sound etc must not contain capital letters or any special symbol other than _

查看更多
残风、尘缘若梦
3楼-- · 2018-12-31 06:36

I had the same error. Error was that, I had placed a file in res/raw folder with invalid filename. As soon as I corrected the file name to a valid one, error was resolved!

Allowed characters for naming a file:-

1. a-z
2. . _
3. 0-9
4. no capital letters

Capital letters were the issue in my case!

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

Try to modify AndroidManifest file.

For example add space and delete this space. After this OPERATION, save project. Resources will be refreshed. It can help.

查看更多
浮光初槿花落
5楼-- · 2018-12-31 06:37

Sometimes you can accidentially add an import to "R", so if at the top of your code you see some weird import about that that you did not add yourself, delete the reference, and everything should go back to normal

查看更多
何处买醉
6楼-- · 2018-12-31 06:37

I had this problem and none of the other guides helped, and then I realized I didn't have the java jdk installed on my system. If you haven't done this either go download the version corresponding to the version of eclipse you installed (x86 or x64)

查看更多
梦寄多情
7楼-- · 2018-12-31 06:37

I found this problem when trying to run the Notepadv3 programme from Googles 'first lesson'..

For me it was an issue with the xml file, due to the API level I was using. I renamed each case of Match_Parent to the older type of Fill_Parent. Oh and if you have already auto-built the project then you need to delete 'import android.R' on NoteEdit.java and Notepadv3.java, clean the project (click 'Project', then 'clean...') before saving.

Solved it for me. Came from this post Android NDK r4 san-angeles problem

Can't believe Google dosen't warn of this problem - I have been setting up another PC to start programming again and even with a bit of prior knowledge this was a pain.. How do you set the API when importing an existing project??? Can't see where there is any dialogue option when you 'File' 'Import' etc ..

Scamparelli

查看更多
登录 后发表回答