找不到 R.layout.activity_main [英] Cannot find R.layout.activity_main

查看:18
本文介绍了找不到 R.layout.activity_main的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一些在线教程来解决多种布局.问题是只要只有一个 XML 文件,我的程序就可以正确构建和编译.当我添加多个 XML 文件时,我收到错误消息,提示 setContentView(R.layout.activity_main);

I was trying to work out with multiple layout using some online tutorials. The thing is my program was building and compiling correctly as long as there was only one XML file. When I added multiple XML files, I am getting errors saying 'activity_main cannot be resolved or is not a field' for the line setContentView(R.layout.activity_main);

事实上,我之前在 R.* 中使用的每个项目现在都在报告错误.我不知道出了什么问题.任何人都可以建议需要做什么吗?

In fact, every item which I used previously in R.* is now reporting error. I don't know what went wrong. Can anyone suggest what needs to be done?

编辑 1:我尝试清理和重建项目,但没有帮助.另外,我正在导入正确的 R.java 文件,如 mypackage.R.java

Edit 1: I tried cleaning and rebuilding the project but that didn't help. Plus, I am importing the correct R.java file as in mypackage.R.java

根据@RubberDuck 的评论,我再次删除文件后,在构建项目后生成了 R.java 文件.但是,当我创建新的 XML 文件并在其中添加元素、构建项目时,R.java 被删除.

According to @RubberDuck's comment, I as soon as I deleted the files again, the R.java file was being generated after building the project. However, when I create new XML files and add elements in it, build the project, R.java gets deleted.

推荐答案

如果您的 XML 包含错误,您生成的文件可能无法构建,请尝试擦除其中的大部分内容并确保 id 和文件名不重复,并且没有大写和空格用过的.如果可行,您可以开始添加内容.

If your XML's contain errors your generated file might not build try erasing most of their content and making sure id's and file names are not duplicated and no capitals and spaces are used. If it works you can start adding stuff.

这篇关于找不到 R.layout.activity_main的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆