14

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?

Ginger McMurray
  • 1,275
  • 2
  • 20
  • 42
  • While I'm at it... My projects don't have density folders for xhdpi so I added that as something to ignore on each project. However, it still reports the error when referenced projects exist. For instance, I've got a project called Library that has the rule set in lint.xml. I've got another project called Service that has the rule set also. Service references Library as an android library. When I run Lint on Library it doesn't report the error, which is good. When I run on Service it doesn't report the error for itself but does report it for Library. :-| – Ginger McMurray Jun 13 '12 at 15:35

7 Answers7

20

Using Project>Clean.

Fixed that problem in my case.

Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
vezucci
  • 386
  • 2
  • 11
16

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.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • That was it. I'm going through 20 different selectors now and recreating them. Yay! :) – Ginger McMurray Jun 13 '12 at 15:52
  • @James - sounds like great fun. :) – Ted Hopp Jun 13 '12 at 16:44
  • 2
    I was about to use the same solution on my project that I started yesterday because I had the same problem yesterday. When I loaded the project today (after having rebooted everything) I actually saw a double-quote character in the file that was not there yesterday! It looks like the IDE got confused about what the file actually contained or something. Very strange. – BlueMonkMN Jan 20 '13 at 13:51
  • 2
    As I continue to work with Eclipse 3.7.2 I have seen on at least 3 occasions now that double-quote characters have been inserted into the XML file without being reflected in the editor. The simplest solution is to close the XML editor and re-open it, at which point the extra characters are displayed. – BlueMonkMN Jan 26 '13 at 23:12
  • You can copy the xml content into notepad and then back into the xml file. This way, you'll be able to see the the extra quotes. – cili Feb 08 '14 at 09:01
13

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

Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
ugochimbo
  • 261
  • 3
  • 5
2

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.

j2R
  • 46
  • 3
1

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 />" ).

0

Analyze -> Inspect code

It worked for me!

-1

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.

Dhwaneel
  • 541
  • 5
  • 8
  • That is incorrect. if the "<" is not there everything after it will be parsed as a property. Since they're nested tags the file won't even compile. – Ginger McMurray Sep 09 '14 at 00:27