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.
Related
I have an app that builds just fine when I build it with ant. But when I import the app into Android Studio, it gives me this error message. Geezzz I really wish I could cut-n-paste text from Android Studio :( so please excuse my screen shot.
Here's my menu.xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="#+id/menu_exit"
android:checkable="true"
android:title="Exit" />
</menu>
#Luksprog's comment The IDE it's complaining because you put your menu file inside the layout folder so the IDE thinks that is a layout file.
You should put menu file under res/menu/menu.xml
For more details about menu resource
https://developer.android.com/guide/topics/resources/menu-resource.html
https://developer.android.com/guide/topics/ui/menus.html
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.
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
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.