Strange Lint Warning - Unexpected text found in layout file: "" - android

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?

Using Project>Clean.
Fixed that problem in my case.

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.

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

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.

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

Analyze -> Inspect code
It worked for me!

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.

Related

Trying to make a ToggleButton with images, getting error: <item> tag requires a 'drawable' attribute or child tag defining a drawable

I am trying to follow a simple tutorial online about making a toggle button in android with images (so it shows images instad of ON/OFF).
It doesn't work. The error I get is
- Binary XML file line #1: <item> tag requires a 'drawable' attribute or child tag defining a drawable
I am using Visual Studio 2019 and coding with Xamarin.
I have a toggle button defined like this in my activity_main.xml:
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/toggleButton1"
android:background="#drawable/toggleButton_emp"
android:id="#+id/toggleButtonEmp"/>
Then I have a "toggleButton_emp.xml" file in "Resources\drawable" which contains:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/faction4" android:state_checked="true"/>
<item android:drawable="#drawable/faction3" android:state_checked="false" />
</selector>
faction4 and faction3 are valid drawables I have added to "Resources\drawable"
I have found many answers for this issue that are most 10 years old, and none help. They often say to make "drawable" first tag but it's already first. Or removing spaces but I don't have any.
Okay so in this case it turned out the problem was that apparently either Android or Visual Studio does not accept .svg format (I assume the former). But there is no error message (format not supported?), no notice, nothing. So I assumed at this day an age, it should either accept it or barf in some way.
The error message I got was also not indicative of real problem in any way. It said that there is no drawable tag, while there clearly was one. So there was no way to guess drawable itself is the culprit.
Anyways, replacing ".svg"s with ".png"s fixed the issue.

"Cannot Resolve Symbol" Error when using android:id="#+android:id/my_id"

When I am adding android:id/background to the namespace, Lint complains that it "Cannot Resolve Symbol" even though I am requesting to add it rather than call it. The code works as written, but the error persists. When I change <item android:id="#+android:id/background" to <item android:id="#+id/background", the application stops working (another call breaks). My question is: why does Lint not recognize me adding android:id/background to the namespace even though a call to it functions well? Is there some better way to give this item an id that won't have Lint throw an error?
All three of the namespace definitions for the items in the layer-list below throw a lint error:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+android:id/background"
android:drawable="#drawable/custom_ratingbar_empty" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/custom_ratingbar_empty" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/custom_ratingbar_filled" />
</layer-list>
I found this and tried running build->clean as suggested with no success.
If you are creating your own id:
"#+id/your_new_id"
if you are accessing your already created id
"#id/your_old_id"
if you are trying to access Android's system created id
"#android:id/system_id"
you can see the difference, if you are creating your own id then you have to add +. Since you are accessing system ID so you don't have to add +
It seems you are using an extra +.
You should remove it, replace as follows #+android:id/background to #android:id/background.
Try to replace #+android:id by #+id and see if it works!

layout-xxx/ causing TypeClass file collision: A resource exists with a different case: '....R$ID.class'

Everything is working fine with my Android project with the standard layout, however whenever I add a new layout-xxx subdirectory, say layout-large, and copy an XML file to it to be my baseline for the new size in question, from that point forward I get the error listed above and the project won't compile.
Location TypeClass file collision: A resource exists with a different case: 'R$ID.class'
If I remove the xml file from the layout-xxx directory everything goes back to working fine. I do have the support-screen tags in the manifest.
I can't possibly need to ID all my views and such inside my layout with seperate names for seperate layout files do I? This would make coding so rediculously conditional that it would not be worth it.
What am I doing wrong? or missing?
I had the same issue today and it was because of my mistake.
I had my menu defined like this
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="#string/action_bar_share_with">
<menu >
<item android:id="#+Id/someid"
android:title="MyMenu"/>
</menu>
</item>
</menu>
Reason of error was Id with capitalized I which should be actually like id
Hope this helps someone

android drawable invalid start tag

I'm trying to set a tabhost selector, as i found an example demonstrating that i should create an xml file in drawable like this :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/hotel_selected"
android:state_selected="true" />
<item android:drawable="#drawable/hotel" />
</selector>
but when compiling, eclipse keep saying that it's an invalid start tag in this file.
please help me solve this.
many thanks.
Found a solution, I created the xml file by using a simple text editor (notepad++) and saved it to /res/drawable and compiled, result: it worked like a charm :)
Ideal solution should be to put the XML file in
/res/xml
i have came across the same error and than solved, i did mistake of adding the xml file under values folder so it was not able to recognise selector tag. i removed it from values folder and added inside the drawable folder and it worked without any error. this was in case of Xamarin.Android.
You can right click on the directory you want to create the XML file, selecect Android xml file, and then edit that file. This solved my issue.
Its seems that there is no any error.
There may be some problem. But you can do one thing, do Project -> Clean , it may resolve your issue.

Android HelloTabWidget issue

I am attempting to run the HelloTabWidget example from here:
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
I am able to build, but once it runs it force closes. I ran the debugger in Eclipse and it looks like the error I am getting is in the res/drawable/ic_tab_artists.xml file.
The error I am getting is:
"org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: tag requires a 'drawable' attribute or child tag defining a drawable"
This is the xml I have for it, pretty straightforward:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http//schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="#drawable/ic_tab_artists_grey" android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="#drawable/ic_tab_artists_white" />
</selector>
I'm just confused because the drawable attribute is there...any ideas? The code/XML I have in my implementation is verbatim what they have in the examples, but it just won't run in the emulator.
<selector xmlns:android="http//schemas.android.com/apk/res/android">
You are missing a colon after http. Perhaps that is the source of the error?
I'm just confused because the drawable attribute is there...any ideas
The only thing I came come up with on why you would get that error is that there's a typo in xmlns:android="http//schemas.android.com/apk/res/android" or a typo in android:drawable, but I don't see a typo in either.
If there were a typo in the xmlns:android= decl, then the android:drawable attribute in item wouldn't be the right drawable attribute, so the run-time would say it isn't there.
If there were a typo in android:drawable, then the run-time error is right: there literally is no drawable attribute in item.

Categories

Resources