【问题标题】:RelativeLayout "Couldn't resolve resource..." Android相对布局“无法解析资源...” Android
【发布时间】:2018-12-06 04:51:09
【问题描述】:

使用以下代码时,我收到错误“无法解析资源@id/item1”这是为什么? id/item1 是在我使用之前添加的,所以我不确定为什么会出现这种情况。

<?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="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/item1"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/noimage" />
    <TextView         
        android:id="@+id/item2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Title"
        android:padding="3dip" 
        android:textSize="20dip"
        android:layout_toRightOf="@id/item1"/>
    <TextView         
        android:id="@+id/item3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Content"
        android:padding="3dip" 
        android:textSize="20dip"
        android:layout_below="@id/item1"/>

</RelativeLayout>

【问题讨论】:

    标签: android android-relativelayout


    【解决方案1】:

    我的代码没有这个错误。

    确保您在其他资源(布局、值、可绘制对象等)中没有错误。然后清理/刷新/构建项目

    【讨论】:

    • 我遇到了同样的错误,并且能够通过重新启动 eclipse 来修复它(清理没有帮助)。虽然对我来说,图形相对布局编辑器在我拖动东西时崩溃了。
    • 如有疑问...重新启动 Eclipse。我可能有一半与 android 相关的问题的答案 -_-
    • 对于那些使用 Android Studio 并且清理没有帮助的人,重新启动也解决了我的问题。
    • 这里相同,尝试构建>清理项目 + 构建>制作项目或构建>重建项目 - 没有任何帮助。重新启动 Android Studio 修复了它。
    【解决方案2】:

    正如 Jose 所说,有时 Android Studio 会发疯。但重启并不总是足够的。

    使您的缓存无效并重新启动。

    文件 -> 使缓存无效/重新启动... -> 无效并重新启动

    等到 AS 完全重新启动和重建。希望它的行为符合逻辑。

    【讨论】:

      【解决方案3】:

      RelativeLayout “Couldn't resolve resource... ... 你需要在 res/values/strings.xml 中定义字符串资源

      【讨论】:

        【解决方案4】:

        当我从其他设备导入项目时,我遇到了同样的错误。 有时,出现此错误的原因是您当前开发环境中的 android SDK 路径错误。

        您需要更改本地 android SDK 路径。

        1 打开local.properties

        2 使用本地SDK路径替换sdk.dir路径。

        3 刷新您的项目并关闭您的 Android Studio。

        4 打开Android Studio,一切正常。

        【讨论】:

          【解决方案5】:

          在 2 台装有 Android Studio 的计算机上遇到此问题。帮助打开 Gradle 并重新同步项目(如之前发布的屏幕截图所示)

          【讨论】:

            【解决方案6】:

            有时 IDE 会发疯。 :) 只需重启 Android Studio,正如 @JasonAxelson、@AlexLockwood、@craned 和 @PhilippGächter 之前所说。

            【讨论】:

              【解决方案7】:

              当您忘记保存 /res/values/strings.xml 时会发生这种情况

              【讨论】:

                猜你喜欢
                • 2010-10-25
                • 2014-09-05
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2019-03-06
                相关资源
                最近更新 更多