“创建自定义属性时,找不到与给定名称匹配的资源”错误

时间:2018-01-12 14:10:08

标签: android xml xml-attribute

我试图为我的类添加自定义xml属性,但即使我不想使用此attrubte,也会发生此错误。我只是在res / values / attrs.xml文件中创建它,就像这样

<?xml version="1.0" encoding="utf-8"?>
<resources>

        <declare-styleable name="my_image">
            <attr name="columns_ratio" format="enum">
                <enum name="1:4" value="3"/>
                <enum name="1:3" value="2"/>
                <enum name="1:2" value="1"/>
                <enum name="1:1" value="0"/>
            </attr>
        </declare-styleable>

</resources>

我在尝试制作项目时收到错误消息。

/home/.../app/build/intermediates/res/merged/debug/values/values.xml
Error:(315) No resource found that matches the given name: id '1:1'.
Error:(314) No resource found that matches the given name: id '1:2'.
Error:(313) No resource found that matches the given name: id '1:3'.
Error:(312) No resource found that matches the given name: id '1:4'.
Error:(315) No resource found that matches the given name: id '1:1'.
Error:(314) No resource found that matches the given name: id '1:2'.
Error:(313) No resource found that matches the given name: id '1:3'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

如果我只是从<declare-styleable> ... </declare-styleable>文件中注释掉这个attrs.xml,则问题就会消失。

为什么会这样?请记住,我甚至没有尝试使用此属性,但它仍在发生。

0 个答案:

没有答案