找不到R.layout.activity_main找不到、layout、activity_main

2023-09-04 11:34:21 作者:ら゛感情一塌糊涂

我试图找出使用一些在线教程多个布局。事情是我的计划是建立和编译正常,只要有只有一个XML文件。当我添加多个XML文件,我得到的错误说activity_main不能得到解决或不是场的行的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);

其实,我在研究用previously每一个项目。* 目前报告的错误。我不知道哪里出了问题。任何人都可以提出什么需要做什么?

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.