Android - Inner element must either be a resource reference or empty

前端 未结 8 1299
天涯浪人
天涯浪人 2020-11-29 04:00

Error Details

AGPBI: {\"kind\":\"error\",\"text\":\"error: \\u003citem\\u003e inner element must either be a resource reference or empty         


        
相关标签:
8条回答
  • 2020-11-29 04:17

    In the the values folder I double clicked the ids.xml file this was causing the issue

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="roll_button" type="id">rollButton</item>
    </resources>
    

    I tried the some of the voted answers:

    <item name="roll_button" type="id">
    

    But I got an error that said:

    The element type "item" must be terminated by the matching end-tag "</item>".
    

    So to fix I just added the matching ending tag:

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

    UPDATE

    I'm new to Kotlin so what I just noticed and what I didn't realize is the <item name="roll_button" type="id" /> needs the forward slash at the end to go before the closing >. If you don't include it then you will get the error I got but if you do include it the accepted answer works.

    0 讨论(0)
  • 2020-11-29 04:21

    I had below error

    error: <item> inner element must either be a resource reference or empty.
    

    In my case I created new test project and deleted the toolbar and fab from activity_main.xml file but these were also in ids.xml file. After deleting both ids from ids.xml file I was able to run. In your ids.xml file you may have lots of ID's but as I created a new project So, It has No IDs.

    In above screenshot you can see the exact file location.

    0 讨论(0)
  • 2020-11-29 04:25

    I simply created this auto-generated file in res/xml/values with empty tags like

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        ...
        <item type="id" name="icon" />
        ...
    </resources>
    

    That did the trick!

    0 讨论(0)
  • 2020-11-29 04:26

    On your Resource File remove the closing tag plus the Body i.e Remove "tv_deviceName"

    and let your resource file be like:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="tv_deviceName" type="id"/>
    </resources>
    
    0 讨论(0)
  • 2020-11-29 04:27

    When declaring id in resources, the body should be empty

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

    For more info please have a look on below link

    https://developer.android.com/guide/topics/resources/more-resources#Id

    So as Oliver Manyasa mentioned, it should be as below

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="tv_deviceName" type="id"/>
    </resources>
    
    0 讨论(0)
  • 2020-11-29 04:30

    I had a similar issue after upgrading to Android Studio 3.2.1

    The error was pointing to this item in ids.xml file

    <item name="mnuActivate" type="id">Activation</item>
    

    As mentioned by the user Sangeet Suresh, I changed it to

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

    That fixed the issue.

    0 讨论(0)
提交回复
热议问题