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 always builds fine. It is 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.
当前回答
我正面临一个错误“无法解析符号R” java文件中的R显示为红色。我已经解出来了。
不保存任何大写字母的图像 像ABC.png。 首先删除映像或重命名它。 清洁项目 重建项目
其他回答
首先检查是否有任何错误在任何xml布局,如果然后解决它首先。
否则,从项目中删除junit依赖项并重新构建项目。
显然,在我的例子中,这个问题通过在结尾添加一个“*”得到了解决
import android.R.*;
这些在Ubuntu 12.04上都不适用。我必须做到以下几点:
sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1
在那之后,我遵循了这个线程中的其他一些建议,做了Build ->清洁项目,一切都很好。
在我的案例中,通过将Android Studio从3.1更新到3.3解决了这个问题
要更新您的Android Studio:文件->设置->系统设置->更新,然后点击立即检查。
我也遇到过类似的问题,我是这样做的:
清洁项目和同步项目与Gradle,
检查buildTools版本在我的sdk
从build gradle (module)中将minSdkVersion从8修改为9
defaultConfig {
applicationId "PackageName"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
但这一切都无济于事。
最后我找到了答案(这对我来说很管用)
从build.gradle(module:app)更改
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
......
....
}
Or
选择文件|项目结构将构建工具版本更改为21.1.1
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)