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.
Related
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.
I am new to android and am following this one tutorial pdf guide.
so far ive not found many unfixable errors.
except when i tried creating a folder in manifest of type menu and created menu_main.xml.
i get attribute is missing from the android name space prefix and a bunch other errors like unexpected text found in layout..
here is the code i pasted from the book. to the menu_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Our add icon will have its own button -->
<item android﹕id="#+id/action_add"
android﹕icon="#drawable/ic_add_white_24dp"
android﹕title="#string/action_add"
app﹕showAsAction="ifRoom" />
</menu>
Turns out all I had to do was delete the colons and re-type them because the spacing between the android:something was a little out of normal.
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!
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.
I find myself again trying to use resources set in the current theme inside my Android application and running into difficulties.
Following the rough guidelines found here for theme attribute value reuse
I was originally trying to create a selector like so
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="?android:attr/selectableItemBackground" />
<item android:drawable="#color/transparent" />
</selector>
where the pressed state drawable is declared like so
<item name="selectableItemBackground">#android:drawable/item_background</item>
in the current ICS themes xml doc themes xml doc . This compiles fine in eclispse (whereas if i spell the attr wrong it will give an error or reffng #android:drawable/item_background directly will inform me the drawable itself is private).
When i run the app i get a
FATAL EXCEPTION: main
E / AndroidRuntime (18815): android.view.InflateException: Binary XML file line #14: Error inflating class <unknown>
without any other useful information apart from the xml file that is using this selector for an ImageViews android:background attribute value. I know that there is a bug where colorStateLists cant be used as backgrounds as mentioned here and maybe this also applys to drawableState lists referencing drawables from the theme. I know however it does work as the post mentioned describes.
Am i missing something here?? I always run into something i dont understand when trying to do stuff like this so would be glad of any pointers.
Thanks for any help
EDIT
as another experiement I tried setting an alias to the referenced drawable in the theme like
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="?android:attr/selectableItemBackground" ></bitmap>
and using this as the background directly but this does not work either. Looking at aliases they are onlyment to ref actual images so this makes sense
EDIT 2
another test an I have found using it directly
android:background="?android:attr/selectableItemBackground"
does actually work. So it seems that using it inside a alias or selector is where it gets unhappy. Strange as i would assume that both background and the same arg
EDIT 3
It seems the theme attr i was pointing at was actually a selector instelf, which im sure didnt help the issue! Thought i wouldve guessed looking at the name of it
I guess i answered the question myself in my edits - main issue i imagine was that i was trying to ref a selector inside a selector.