{"id":910,"date":"2013-09-28T16:49:30","date_gmt":"2013-09-28T08:49:30","guid":{"rendered":"http:\/\/www.vcoo.cc\/blog\/?p=910"},"modified":"2013-09-29T22:18:58","modified_gmt":"2013-09-29T14:18:58","slug":"r-cannot-be-resolved-to-a-variable","status":"publish","type":"post","link":"https:\/\/vcoo.cc\/blog\/910\/","title":{"rendered":"Android\uff1aR cannot be resolved to a variable"},"content":{"rendered":"<p>Android\u5f00\u53d1\u4e2d\u9047\u5230\u8fd9\u6837\u7684\u9519\u8bef\uff1a<strong>R cannot be resolved to a variable<\/strong>\uff0c\u7f51\u4e0a\u7684\u89e3\u51b3\u65b9\u6cd5\u5404\u79cd\u90fd\u8bd5\u8fc7\u6ca1\u6709\u89e3\u51b3\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u8fd9\u6837\u7684\u539f\u56e0\u3002<\/p>\n<p>\u6211\u7535\u8111\u7684\u5f00\u53d1\u73af\u5883\u4e0d\u7b97\u662f\u5168\u65b0\u642d\u5efa\u7684\uff0c\u5176\u4e2d\u7684Android SDK\u662f\u5f88\u65e9\u4e4b\u524d\u5c31\u6709\u4e86\uff0cEclipse\u662f\u65b0\u5b89\u88c5\u7684\uff0c\u4e8e\u662f\u6211\u4eceGoogle\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u4e86\u4e00\u4e2a\u6700\u65b0\u7684SDK\u628a\u65e7Android-SDK\u6539\u540d\uff0c\u8fd9\u6837Eclipse\u542f\u52a8\u5c31\u52a0\u8f7d\u4e86\u65b0SDK\uff0c\u7adf\u7136\u95ee\u9898\u8fd9\u6837\u89e3\u51b3\u4e86\u3002<\/p>\n<p>\u7f51\u4e0a\u6709\u4eba\u8bf4\u662f\u6709XML\u6709\u9519\u8bef\u5bfc\u81f4\u7684\uff0c\u53ef\u662f\u6211\u5168\u65b0\u5efa\u7684\u9879\u76ee\u4e5f\u662f\u62a5\u8fd9\u6837\u7684\u9519\uff0c\u5982\u679c\u5927\u5bb6\u9047\u5230\u8fd9\u6837\u7684\u9519\uff0c\u90a3\u4e48\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5e94\u8be5\u662f\uff1a<\/p>\n<p>\u5168\u65b0\u5efa\u4e2a\u9879\u76ee\u770b\u662f\u5426\u4f9d\u7136\u51fa\u9519\uff0c\u5982\u679c\u662f\u7684\u8bdd\uff0c\u90a3\u4e48\u597d\uff0c\u91cd\u65b0\u66f4\u65b0 Android SDK \u5427\uff0c\u53cd\u6b63\u6211\u662f\u89e3\u51b3\u4e86\uff0c\u4e0d\u4e00\u5b9a\u80fd\u89e3\u51b3\u5927\u5bb6\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0b\u6765\u81ea\u7f51\u7edc\u7684\u65b9\u6cd5\uff1a<\/p>\n<blockquote><p>1. \u68c0\u67e5Android \u7684SDK\u662f\u5426\u4e22\u5931\u9700\u8981\u91cd\u65b0\u4e0b\u8f7d\uff0c\u68c0\u67e5build path<br \/>\n2.\u786e\u4fddclass\u6ca1\u6709import Android.R\uff1b<br \/>\n3,\u9519\u8befclass\u5f15\u7528\u7684layout\u7684xml\u6587\u4ef6\u6ca1\u6709\u9519\u8bef<br \/>\n4.\u68c0\u67e5AndroidManifest.xml\u6587\u4ef6\uff0c\u91cc\u8fb9\u7684package\uff0clayout\u914d\u7f6e\u6587\u4ef6\uff0cstrings.xml\u7b49\u7684\u5b57\u7b26\u4e32\u5168\u90e8\u4e66\u5199\u6b63\u786e<br \/>\n5.layout\u7684xml\u6587\u4ef6\u4e2d\u5f15\u7528\u7684strings.xml\u4e2d\u7684\u5b57\u7b26\u4e32\u62fc\u5199\u5b8c\u5168\u6b63\u786e<br \/>\n6.\u5728layout \u7684xml\u6587\u4ef6\u624b\u5199\u6dfb\u52a0\u4e00\u4e2a\u63a7\u4ef6\uff0c\u770bid\u80fd\u5426\u5728R.java\u4e2d\u81ea\u52a8\u751f\u6210\uff0c\u5982\u679c\u4e0d\u80fd\uff0c\u90a3\u5f88\u5927\u53ef\u80fd\u5c31\u662f\u8fd9\u4e2alayout \u7684xml\u6587\u4ef6\u6709\u95ee\u9898\uff0c\u67e5\u770b\u683c\u5f0f\u662f\u5426\u4f7f\u7528\u6b63\u786e\uff0c\u6216\u8005\u5305\u542b\u4ec0\u4e48\u975e\u6cd5\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u8c03\u7528\u5230\u4e86\u4e0d\u6b63\u786e\u7684\u5b57\u7b26\u4e32\uff0c\u7b49\u7b49\uff0c\u53ef\u4ee5\u4f7f\u7528\u6392\u9664\u6cd5\uff0c\u6328\u4e2a\u53bb\u6389\u63a7\u4ef6\uff0c\u76f4\u5230\u53d1\u73b0error message\u6d88\u5931\u6216\u8005id\u80fd\u5728R.java\u4e2d\u81ea\u52a8\u751f\u6210\u3002<br \/>\n7.\u5220\u6389gen\u6587\u4ef6\u5939\uff0c\u4f7fR.java\u91cd\u65b0\u81ea\u52a8\u751f\u6210\u4e00\u6b21\uff0c\u5982\u679c\u4e0d\u80fd\u751f\u6210\uff0c\u7ee7\u7eed\u68c0\u67e5layout\u7684xml\u6587\u4ef6\u662f\u5426\u6709\u5982\u4e0a\u4e0d\u6613\u53d1\u89c9\u7684\u95ee\u9898<br \/>\n8.Clean project \uff0c\u91cd\u65b0build\uff0c\u6216\u8005\u91cd\u65b0import project\u3002<br \/>\n9.\u91cd\u542feclipse<br \/>\n10.\u91cd\u542f\u7535\u8111\uff0c\u4ee5\u9632Android \u865a\u62df\u673a\u7684\u95ee\u9898<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Android\u5f00\u53d1\u4e2d\u9047\u5230\u8fd9\u6837\u7684\u9519\u8bef\uff1aR cannot be resolved to a variable\uff0c\u7f51\u4e0a\u7684\u89e3\u51b3\u65b9\u6cd5\u5404\u79cd\u90fd\u8bd5\u8fc7\u6ca1\u6709\u89e3\u51b3\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u8fd9\u6837\u7684\u539f\u56e0\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[275,89,198,94,121],"class_list":["post-910","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-java","tag-198","tag-94","tag-121","cat-76-id"],"_links":{"self":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/posts\/910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/comments?post=910"}],"version-history":[{"count":0,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/posts\/910\/revisions"}],"wp:attachment":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/media?parent=910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/categories?post=910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/tags?post=910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}