简体   繁体   English

在setContentView(R.layout.activity_main)中创建的第一个应用程序上的Eclipse和Android ADT错误

[英]Eclipse and Android ADT error on the first app created in setContentView(R.layout.activity_main)

I have no word. 我没话说 How is possible that Google permit a thing like this?!?! Google怎么可能允许这样的事情?!?! I've read a thousand of documentation before to download Eclipse + Android ADT. 在下载Eclipse + Android ADT之前,我已经阅读了成千上万的文档。 After installation, like every time I made an installation of a new development system, I try to write the simple app: "hallo world". 安装后,就像每次安装新开发系统一样,我尝试编写一个简单的应用程序:“ hallo world”。 How is possible that a simply stuff like "hallo world" don't goes?!? 像“你好世界”这样的简单东西怎么可能不消失?!

First the error on "R"... that brings the error "cannot be resolved to a variable". 首先,“ R”上的错误...导致错误“无法解析为变量”。 The fix is to add: 解决方法是添加:

import android.R;

Ok... was easy. 好...很简单。 One minute on Stackoverflow and the solution is served. 在Stackoverflow上等待一分钟,即可解决问题。 Then..... BANG... immediatly the second error: 然后..... BANG ...立即出现第二个错误:

  • setContentView(R.layout.activity_main); setContentView(R.layout.activity_main); generates "activity_main cannot be resolved or is not a field" 生成“ activity_main无法解析或不是字段”
  • getMenuInflater().inflate(R.menu.main, menu); getMenuInflater()。inflate(R.menu.main,menu); generates "main cannot be resolved or is not a field". 生成“主要无法解决或不是字段”。

At this point I've read many (too much) post over this issue, but without to see the light... 在这一点上,我已经读了很多(太多)关于这个问题的文章,但是却看不见光明...

I repeat, is incredible that a system to develop app for the most widespread mobile operating system has errors at the first installation..... Sure will be my fault... 我再说一遍,令人难以置信的是,为最广泛的移动操作系统开发应用程序的系统在首次安装时出现错误.....肯定是我的错...

Any suggestion is appreciated ? 有什么建议值得赞赏吗?

You should never import android.R. 您永远不要导入android.R。

You should instead import com.example.yourapp.R 您应该改为导入com.example.yourapp.R

android.R is full of resources that are baked into the Android SDK. android.R充满了包含在Android SDK中的资源。 Your own resources are not in that class. 您自己的资源不在该类中。

I've finally understood. 我终于明白了 When I created my first project I've not used the convention com.example.myapp but "my convention" com.myname.myapp (like I can do with xCode). 创建第一个项目时,我没有使用约定com.example.myapp,而是使用了“我的约定” com.myname.myapp(就像我可以使用xCode一样)。 Now using import 现在使用导入

com.example.myapp.R; com.example.myapp.R;

working.... But now the question is: I can't change the word "example" in the package's name? 可以。...但现在的问题是:我不能在包装名称中更改“ example”一词吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM