Android Studio – Cannot resolve symbol ‘R’

来源:互联网 发布:java post 二进制 编辑:程序博客网 时间:2024/06/05 09:11

因要用到,所以最近学了点Android开发,用的编译器是亲儿子,也是新生儿 Android Studio。

今天在调试的时候,Android Studio 报了一个莫名其妙的错误Cannot resolve symbol 'R'让人不知所措。因为这东西根本不归我管啊,怎么会出现 Cannot resolve symbol 这种错误呢?

谷歌了一下,找到解决方法如下:

  • Build -> Clean Project
  • Tools -> Android -> Sync Project With Gradle Files

不行就多试几次!就好了!

原因是什么?估计是没自动生成 R.java 文件。为什么会出现这样的问题?因为Android Studio是新生儿。。。。

再来看看一位遇到过此问题的网友的内心独白!Just For Fun!^_^

In every instance in all of my classes where i reference R.id.something the R is in red and it says “cannot resolve symbol R”, also every time there is R.layout.something it is underlined in red and says “cannot resolve method setContentView(?)”. The project however never fails to build and does work fine. It is just annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from eclipse. I am using what i believe to be the most recent version of android studio and the project was created with android studio and worked without any cannot resolve R problems. I would like to know what causes this if anyone knows.

UPDATE: Please accept my apologies for never updating this. I solved my own problem since this has been posted. At the time android studio was brand new and I was also a brand new developer. I should never had been using android studio, I never realized how unfinished it was. Thanks everyone for the support in trying to help since this has been posted. Ironically the actual “answer” to this question has been deleted and cannot be undeleted. I feel that my original answer is the solution to this problem, in short don’t use android studio if you are new to android development.

0 0
原创粉丝点击