错误:无法解析activity_main或没有字段 [英] error :activity_main can not be resolved or not a field
问题描述
得到上述错误.遵循了这个
但是没有找到解决方案.检查了我的资源文件,所有但没有用的地方为我提供了一个可行的解决方案.在这里放置activity_main.xml 和
but didn't find solution.checked my resource file and all but no use suggest me sutable solution for this.here placing the activity_main.xml and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="87dp"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_centerVertical="true"
android:text="Button2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="52dp"
android:text="Button" />
</RelativeLayout>
推荐答案
更改
setContentView(R.id.activity_main);
到
setContentView(R.layout.activity_main);
从文档中
从布局资源设置活动内容.资源将被放大,将所有顶级视图添加到活动中.
Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.
如果您在gen
文件夹中的R.java
中查找,则存在不同的类. R.id
表示您给定View
的id
. R.layout
用于创建的layout
文件.
setContentView either takes a
布局or a
View . Not an
id of a
View`.
If you look in R.java
in the gen
folder, there are different classes. R.id
is for an id
that you give a certain View
. R.layout
is for a layout
file that you create.
setContentVieweither takes a
layoutor a
View. Not an
idof a
View`.
这篇关于错误:无法解析activity_main或没有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!