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

For me somehow the Project properties; Android; Project Build Target was not set. I chose a Android version there (e.g. 4.2) and it fixed it.

查看更多
明月照影归
3楼-- · 2018-12-31 06:26

What you really need to do it just install "build-tools" from sdk manager, and r.java will be generated automatically.

查看更多
人间绝色
4楼-- · 2018-12-31 06:26

Check the androidmanifest.xml file and layoutfolder xml files. They should be created properly as the starting and ending clause in xml should be placed properly. Update the files, clean and build. And all set!

查看更多
无与为乐者.
5楼-- · 2018-12-31 06:29

I got this when I renamed a project. Although the project is renamed, some references are not. Clearing lint, and then rerunning lint helped. (Right click project > Android Tools > Clear Lint Markers, then Run Lint)

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

For me, there was a missing slash at the end of my SDK. In Eclipse > Preferences > Android > SDK Location

For example, change

/home/matt/android-sdk-linux

to

/home/matt/android-sdk-linux/
查看更多
与君花间醉酒
7楼-- · 2018-12-31 06:32

For me the error got fixed by making some changes in Android SDK Manager.
Whatever be the latest API level available, install its "SDK Platform". For me latest API level available was 16, so I installed its's SDK Platform as shown in the image below. It works fine now.

Screenshot of Android SDK Manager after fixing the problem
Cheers, Mayank

查看更多
登录 后发表回答