【发布时间】:2016-05-09 10:05:54
【问题描述】:
我收到一条错误消息“Cannot resolve symbol '@id/myLabel'”。
以下元素也有同样的错误:
"Cannot resolve symbol '@id/numberStudents'"
"Cannot resolve symbol '@id/accept'"
请帮我解决这个问题。 我的 xml 示例粘贴在下面。
谢谢, 阿比拉什·卡达拉。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/myLabel"
android:text="Name of student:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/numberStudents"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/myLabel"
/>
<Button
android:id="@+id/accept"
android:text="Accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberStudents"
android:layout_alignParentRight="true"
android:layout_marginLeft="10px"
/>
<Button
android:id="@+id/cancel"
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/accept"
android:layout_alignTop="@id/accept"
/>
</RelativeLayout>
【问题讨论】:
-
尝试清理你的项目。
-
清理或重建即可。
-
将
android:layout_below="@id/myLabel"更改为android:layout_below="@+id/myLabel"和其他所有相同,它可能会有所帮助 -
使用@+id 代替@id。例如android:layout_alignTop="@+id/accept"。如果可以接受,请投票。
-
大家好,@+id 用于声明,@id 用于使用声明的元素。
标签: java android xml android-layout