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.
当前回答
我在清理建筑。Gradle和这个错误出现。
一大堆“清理和重建”的答案。这些对我都没用。
最后,我发现我无意中复制粘贴了build.gradle中错误的“命名空间”名称。修复了它,它运行。
其他回答
我不得不在android studio中导入我的R包。例如:import com.example。<包名称>。R
我有未解决的R问题,因为相同的image.png文件在两个地方。一个在res>anim和相同的文件在res>drawable-hdpi。这导致R无法解决。 问题是我制作了一个启动画面图像,并反复将其从Moray图形目录直接移动到Android项目中。我一定是不小心把它扔进了res>anim文件夹。我通过从res>anim文件夹中删除重复的图像文件来解决这个问题,Android工作室纠正了自己。
这个符号看起来很好用。
android:id="@+id/viewID"
Android Studio的设计面板似乎不太好用。
只需从根包中导入R符号
import rootpackage.R;
没有重建,同步或其他事情…
在我的情况下,我试图清理和重建项目。这个问题没有修复,因为在布局文件中存在错误。为了重新创建,我在应用程序名称空间的属性上添加了一个错字。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/add_user"
android:icon="@android:drawable/ic_menu_add"
android:title="Add User"
app:showAsActioin="always"
/>
</menu>
Android工作室没有检查应用程序名称空间的属性,似乎文件是无错误的。现在,在构建项目时,它说无法解析符号“R”。错误显示在构建日志中。
修复错字修复它,手表上的Android问题部分的构建日志。
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)