当前位置: 首页 > 知识库问答 >
问题:

如何修复“错误:内部元素必须是资源引用或为空”?

齐高阳
2023-03-14

今天我决定更新Android Studio,因为我安装的3.1版本似乎有点过时了。升级后,由于某种< code >错误,构建项目失败:

全输出:

Android resource compilation failed
Output:  E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2400: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2401: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2402: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2403: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2404: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2405: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2406: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2407: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2408: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2409: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2410: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2411: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2412: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2414: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2415: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2416: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2418: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2419: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2420: error: <item> inner element must either be a resource reference or empty.
E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2421: error: <item> inner element must either be a resource reference or empty.

Command: C:\Users\Manuel\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\f6068c12ec105318abf65b42f5ee35d5\aapt2-3.2.0-4818971-windows\aapt2.exe compile --legacy \
        -o \
        E:\Desktop\testandroidstudio\app\build\intermediates\res\merged\debug \
        E:\Desktop\testandroidstudio\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Daemon:  AAPT2 aapt2-3.2.0-4818971-windows Daemon #0

错误指向构建文件values.xml,检查它,我想可能问题出在我的arrays.xml文件上。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="dice_types">
        <item>@string/dice4</item>
        <item>@string/dice6</item>
        <item>@string/dice8</item>
        <item>@string/dice10</item>
        <item>@string/dice12</item>
        <item>@string/dice20</item>
        <item>@string/dice100</item>
    </string-array>
    <string-array name="dice_types_int">
        <item>4</item>
        <item>6</item>
        <item>8</item>
        <item>10</item>
        <item>12</item>
        <item>20</item>
        <item>100</item>
    </string-array>
    <string-array name="spell_numbers">
        <item>@string/spell_level_0</item>
        <item>@string/spell_level_1</item>
        <item>@string/spell_level_2</item>
        <item>@string/spell_level_3</item>
        <item>@string/spell_level_4</item>
        <item>@string/spell_level_5</item>
        <item>@string/spell_level_6</item>
        <item>@string/spell_level_7</item>
        <item>@string/spell_level_8</item>
        <item>@string/spell_level_9</item>
    </string-array>
    <string-array name="ability_shorts">
        <item>STR</item>
        <item>DEX</item>
        <item>CON</item>
        <item>INT</item>
        <item>WIS</item>
        <item>CHA</item>
    </string-array>
</resources>

我谷歌了一下,发现错误是由这样解析的项目引起的:

<item name="item_1" type="id">Item 1</item>

并且可以通过将代码替换为如下内容来解决:

<item name="item_1" type="id"/>

但是我应该用字符串数组做什么呢?。

共有1个答案

吕鹏
2023-03-14

听起来您实际上无法将硬编码的值放入项目标记中。将它们放在@strings文件和@integers文件中,然后在项目标记中引用它们?

 类似资料:
  • 我的项目升级Gradle到4版后无法编译,Android Studio抛出错误: Android 资源编译失败 C:\用户\用户\AndroidStudioProjects\grow_director_v2_net\app\build\中间\增量\合并DevDebugResources\merged.dir\values\values.xml:1475:错误:内部元素必须是资源引用或为空。C:\用

  • 错误详细信息 生成环境 Android Studio 3.1.4 minSDKversion=21 目标SDKVersion=28 CompilesDKVersion=28 BuildToolsVersion=“28.0.2”

  • 我正在使用multer和cloudinary构建一个图像上传应用程序。我已经使用dotenv正确配置了环境变量。然而,当我尝试使用Cloudinary上传文件时,我得到了错误“必须提供api_密钥”。 Cloudinary API凭据的提供和配置正确,如下代码所示: 阴云密布。js 埃文先生 这个env文件在我的应用程序中也是正确必需的。js文件: app.js 如果我在cloudinary.js

  • 我正在添加ReCAPTCHA到一个(引导哲基尔)网站,有多个联系人表单。页脚有一个弹出模式,偶尔有一个“立即联系我们”部分,还有几个页面上有一个“请求更多关于____的信息”。 由于我在一个页面上有多个联系人表单,所以我需要显式呈现每个recaptcha。代码如下: 在我的JavaScript中: 在页脚中(包含在所有页面中) (并在页脚底部) 这在一个有两个单独联系人表单的页面上工作得很好(即我

  • 我把我的代码放在XML验证网站,它给了我这个错误: 第 8 行:4 文档中根元素后面的标记必须格式正确。 有问题的行是

  • 以下是错误日志: 这里有一个相关的问题:https://stackoverflow.com/a/14370767,它建议使用SO_SNDTIMEO套接字选项设置发送超时。