出来。activity_find_contact不能被解析,也不能是一个字段。

时间:2022-12-13 20:53:23

I am brand new to android development so please bear with me. I have encountered a problem when I create a new activity. In the newly created activity there is the auto-generated overridden method 'onCreate':

我是android开发的新手,所以请耐心等待。当我创建一个新的活动时,我遇到了一个问题。在新创建的活动中,有自动生成的覆盖方法“onCreate”:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_find_contact);
    // Show the Up button in the action bar.
    setupActionBar();
}

On the line setContentView(R.layout.activity_find_contact);, I get the error: activity_find_contact cannot be resolved or is not a field.

在行setContentView(R.layout.activity_find_contact)上,我得到了错误:activity_find_contact不能被解析,也不能是一个字段。

I have looked up other questions on this topic. Some say to just restart eclipse - this didn't work. Others said to try cleaning the project - this didn't work either. The most promising answer said to delete the line:

关于这个话题,我已经查阅了其他的问题。一些人说要重新启动eclipse——这不起作用。另一些人则说要尝试清理这个项目——这也不管用。最有希望的答案是:

import android.R;

进口android.R;

I tried this, and of course then R gets the error: R cannot be resolved to a variable. So I followed the advice to import your.application.package.R; - which in my context translates to import com.example.databasetest.R;. However this just brings up the error the import com.example.databasetest.R; cannot be resolved to a type.

我尝试了这个,当然R得到了这个错误:R不能被解析为一个变量。所以我听从了你的建议。-在我的语境中翻译为导入com.example.databasetest.R;但是,这只会带来导入com.example.databasetest.R的错误;无法解析为类型。

So now I'm stumped and back to square one. Any ideas?

所以现在我被难住了,回到了起点。什么好主意吗?

2 个解决方案

#1


6  

R files are automatically generated.. so you don't need to import it or do anything. The error is because there is something wrong in your xml file or files.Got through your xml files and see if you can find any errors.

R文件自动生成。所以你不需要导入它或做任何事情。错误是因为您的xml文件或文件有问题。通过xml文件,看看是否能找到错误。

These errors might even be typos.So make sure all of it is correct and cleaning and running the project again should get your code working

这些错误甚至可能是拼写错误。因此,确保所有的代码都是正确的,并且再次运行这个项目应该能让你的代码工作起来。

#2


2  

Do not use the following import

不要使用以下导入?

import android.R;

This errors comes because when we create new app we delete hello world textview but that is referenced in strings.xml in res > values > strings

这个错误是因为当我们创建新应用程序时,我们会删除hello world textview,但这是在字符串中引用的。xml在res >值>字符串。

go to that and remove hello world , clean project and errors should be gone ...

到那个地方去,删除hello world,清理项目和错误应该消失……

#1


6  

R files are automatically generated.. so you don't need to import it or do anything. The error is because there is something wrong in your xml file or files.Got through your xml files and see if you can find any errors.

R文件自动生成。所以你不需要导入它或做任何事情。错误是因为您的xml文件或文件有问题。通过xml文件,看看是否能找到错误。

These errors might even be typos.So make sure all of it is correct and cleaning and running the project again should get your code working

这些错误甚至可能是拼写错误。因此,确保所有的代码都是正确的,并且再次运行这个项目应该能让你的代码工作起来。

#2


2  

Do not use the following import

不要使用以下导入?

import android.R;

This errors comes because when we create new app we delete hello world textview but that is referenced in strings.xml in res > values > strings

这个错误是因为当我们创建新应用程序时,我们会删除hello world textview,但这是在字符串中引用的。xml在res >值>字符串。

go to that and remove hello world , clean project and errors should be gone ...

到那个地方去,删除hello world,清理项目和错误应该消失……