【发布时间】: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