【问题标题】:"Error: ':' is not a valid resource name character" after upgrading to Android Studio 3.3 [duplicate]“错误:':'不是有效的资源名称字符”升级到 Android Studio 3.3 [重复]
【发布时间】:2019-02-10 16:36:08
【问题描述】:

我一直在开发一个定期更新的旧 Android 项目。 现在,升级到 Android Studio 3.3 后,我收到了这个错误:

Error: ':' is not a valid resource name character

在以下 res/layout 文件中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="#4d4d4d">

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/deleteAll">
    </ListView>

    <TextView
        android:id="@+id/favourite"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/fav"
        android:textColor="@color/white" />

    <Button
        android:id="@+id/deleteAll"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/yellow_button_event"
        android:text="@string/delete_fav" />        
</RelativeLayout>

我在 StackOverflow 上找到了很多关于这个问题的答案,但没有一个能让我弄清楚我的问题是什么。

你知道它有什么问题吗?

【问题讨论】:

  • 我在 3.3.0 中遇到了一大堆资源错误。清理、使缓存失效或删除临时文件夹的组合都无法修复它。不幸的是,降级到 3.2.1(在项目 build.gradle 中)是修复它的唯一方法。
  • 也许检查你的字符串文件,因为它可能有一些资源被错误地命名为应该转义的字符?
  • @FrancislainyCampos 你的意思是strings.xml 文件吗?如果我在日志中看到给定的 xml 文件,为什么会出现问题?
  • 是的,这就是 strings.file。有时这类错误就是由此而来。这也是我们为资源命名的地方,所以这是我的猜测。

标签: android xml android-studio android-layout


【解决方案1】:
android:id="@+id/android:list"

这应该是你的错误。现在,除非您实现一些我不熟悉的功能,否则我知道这是不好的命名约定。我认为这个特定角色直到 3.3 才被强制执行

我会用..

android:id="@+id/list_favourite

这里是一个great website,带有各种 Android 命名约定。

【讨论】:

  • 感谢您的回复,但是没有用。
  • 如果即使在清理/构建之后仍然无法正常工作,那么我会删除每个视图/元素,然后慢慢添加它们以缩小具体导致此问题的行。
  • 使用此答案解决:stackoverflow.com/a/54495619/2516399(与您的相似)
猜你喜欢
  • 2016-05-16
  • 1970-01-01
  • 1970-01-01
  • 2020-02-26
  • 2015-06-13
  • 2017-04-18
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多