【问题标题】:Android "Cannot resolve symbol '@id/myLabel"Android“无法解析符号'@id/myLabel”
【发布时间】: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


【解决方案1】:

Rebuild project 为我工作。

【讨论】:

    【解决方案2】:

    这是因为您声明 id 像这样 @+id/accept 并使用像这样 @id/accept 的另一个地方。

    【讨论】:

    • 试着简单地扩展你的答案。
    • 哦,你正在声明@+id/accept,你可以尝试访问
    【解决方案3】:

    尝试从磁盘重新加载所有内容 [Ctrl + Alt + Y]

    【讨论】:

      【解决方案4】:

      尝试使缓存无效并重新启动,对我有用:)

      【讨论】:

        猜你喜欢
        • 2017-03-05
        • 1970-01-01
        • 1970-01-01
        • 2018-05-03
        • 1970-01-01
        • 2016-06-15
        • 2017-02-09
        • 2015-12-28
        • 2016-03-03
        相关资源
        最近更新 更多