Strange Lint Warning - Unexpected text found in layout file: “”

有些话、适合烂在心里 提交于 2019-12-04 16:45:40

问题


I've got the following selector defined in button_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:state_pressed="true" 
           android:state_enabled="true"
           android:drawable="@drawable/button_settlement_background_pressed" />
       <item android:state_enabled="true"
           android:drawable="@drawable/button_settlement_background_normal" />
       <item android:state_enabled="false"
           android:drawable="@drawable/button_settlement_background_disabled" />
       </selector>

When I run lint I get the following warning: Unexpected text found in layout file: "". It says it's happening at line 4 in "drawable". All of the referenced drawables exist in /res/drawable.

Does anyone know what could be causing this? I can ignore the warning but I'd rather fix it if possible.

Also, I get warnings for unused strings and icons when they're only referenced in AndroidManifest.xml. Is there a way to fix those instead of ignoring them?


回答1:


Perhaps there's an invisible character somewhere in the white space. I'd try recreating the xml from scratch (not using copy-and-paste, which would just copy the problem, if that's what's happening). I'd also clean and rebuild the project.

As far as the unused resource warnings, I don't think there's a way to control this. The problem of false positives is hugely worse for library projects. Android lint is a fairly new tool and (in my opinion) still has a lot of rough edges.




回答2:


Using Project>Clean.

Fixed that problem in my case.




回答3:


You can also Format the xml file (CTRL + SHIFT + F). The extra characters would be displayed.




回答4:


typically, this would happen when you inserting something like "android:id=" without a newline and using eclipse's auto completion, like this:

<LinearLayout
            android:id= >
                       ^

here type enter, the code would appears to be like this:

<LinearLayout
                android:id="@+id/

the character '>' has been erased and '"' become invisible.

use ctrl+shift+f to format the file to find the hidden characters.




回答5:


I found that if I closed the file I had the hidden character on, then reopened the same file. The character was no longer hidden (and typically was just after the />, for example />" ).




回答6:


Analyze -> Inspect code

It worked for me!




回答7:


In XML file, tags contain attributes. consider the line: (last ">" should not be there) ...

<selector xmlns:android="http://schemas.android.com/apk/res/android">

Make sure that the tag on first line does not contain">".

Replace above code with: <selector xmlns:android="http://schemas.android.com/apk/res/android" ... </selector>

Now other elements are under selector tag. I hope this helps.



来源:https://stackoverflow.com/questions/11018162/strange-lint-warning-unexpected-text-found-in-layout-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!