Android: R cannot be resolved to a variable

本文提供了多种解决Android开发中R类无法解析问题的方法,包括检查SDK、清理项目、重启开发工具等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://hi.baidu.com/mycollection/blog/item/0f53842f8a5f7b251f3089c5.html

http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error

R is an automatically generated class that holds the constants used to identify your resources. If you don't have an R.java file (it would be gen/eu.mauriziopz.gps/R.java in Eclipse with the 1.5 SDK) I would recommend closing and reopening your project or going to Project > Build all (and selecting "Build Automatically" while there as recommended by Josef). If that doesn't work than try making a new project, if the problem is recreated than post here again and we'll go into more detail.

===================================================================


Android开发过程中,碰到R cannot be resolved to a variable的报错信息,好像没有很确定的错误原因,一般来说,我总结出几个可能的解决方法,希望试过以后管用。。。

 

1. 检查Android 的SDK是否丢失需要重新下载,检查build path

2.确保class没有import Android.R;

3,错误class引用的layout的xml文件没有错误

4.检查AndroidManifest.xml文件,里边的package,layout配置文件,strings.xml等的字符串全部书写正确

5.layout的xml文件中引用的strings.xml中的字符串拼写完全正确

6.在layout 的xml文件手写添加一个控件,看id能否在R.java中自动生成,如果不能,那很大可能就是这个layout 的xml文件有问题,查看格式是否使用正确,或者包含什么非法字符串,或者调用到了不正确的字符串,等等,可以使用排除法,挨个去掉控件,直到发现error message消失或者id能在R.java中自动生成。
7.删掉gen文件夹,使R.java重新自动生成一次,如果不能生成,继续检查layout的xml文件是否有如上不易发觉的问题(我就是这样解决的,有点暴力!)

8.Clean project ,重新build,或者重新import project。

9.重启eclipse

10.重启电脑,以防Android 虚拟机的问题

 

再不行的话,就自求多福了,查查其他地方

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值