安卓项目突然毁了,找不到R对象



R无法解析为变量。所以我尝试进行"修复项目设置",但它无法识别其所有子内容,例如来自我的xmlR.id.XR.drawable.Y的对象,它们都没有被识别。

我只是试着跟随http://developer.android.com/guide/topics/ui/controls/pickers.html引导并添加这样的类,以便有一个选择时间的对话框。

    Description Resource    Path    Location    Type
users cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 170    Java Problem
ic_launcher cannot be resolved or is not a field    MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 159    Java Problem
about cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 136    Java Problem
menu_user cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 133    Java Problem
imp_logo cannot be resolved or is not a field   MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 198    Java Problem
activity_main cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 44 Java Problem
timerCB cannot be resolved or is not a field    MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 64 Java Problem
timerTime cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 65 Java Problem
statusText cannot be resolved or is not a field MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 66 Java Problem
timerText cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 67 Java Problem
start_button cannot be resolved or is not a field   MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 68 Java Problem
stop_button cannot be resolved or is not a field    MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 69 Java Problem
activity_main cannot be resolved or is not a field  MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 123    Java Problem
menu_url cannot be resolved or is not a field   MainActivity.java   /RemoteSwitch/src/com/example/remoteswitch  line 130    Java Problem

执行项目->清洁几次。

然后构建项目。

如果在gen文件夹中仍然找不到R.java,请检查layout文件中是否有任何错误,例如,检查所有xml filesdrawables是否仅以小写字母命名。

删除这些错误后,请再次进行清理和生成。

只需删除import android.R即可工作。

上面的答案清楚地说明了这一点。看看你的布局文件,我给你一个提示:当我用strings.xml文件填充时,我发现,在那里复制一些颜色时,我用标签关闭了标签。这是一件容易被忽视的事情,我打算写一个类来检测这一点,因为显然这不会很快得到修复(我所说的修复是指至少给我们一个通知)。

  • 通过选择项目-清理来清理项目
  • 如果未创建R.java,请删除gen文件夹,然后手动重新创建它,右键单击,构建路径-用作源文件夹,重建项目
  • 如果R.java仍然不存在,则某些XML文件可能包含错误,请检查
  • 如果项目的来源是svn存储库,则可能存在一些编译器无法识别的不可见配置文件。右键单击您的项目-属性-资源-资源过滤器-添加-排除所有-文件和文件夹-名称匹配.svn
  • 如果你下载并导入了你的项目,请检查目标(SDK)并确保你安装了所需的软件包

最新更新