attribute is missing the android namespace prefix - android

Im creating an android app which uses a menu.xml file in the res folder. But I'm getting the above error. What does it mean? How can I fix it?
menu.xml:
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item id="#+id/my_location"
android:icon="#drawable/my_location"
android:title:="Current location" />
<item id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View" />
<item id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view" />
</menu>

Change <item id="#+id/my_location" to <item android:id="#+id/my_location". This in all three places.
Also, in here: android:title:="Current location" remove the colon after title.

You also need to make sure the following two lines are in your attributes list:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
If you omit those, Eclipse will just give you the "missing android prefix" error.

Believe it or not, for anyone who tries to work through examples in downloaded books, you may need to make sure you have true quotation marks as the compiler understands them. I'd been getting the same error as the OP, and many similar parse errors as I tried to modify an XML file in small ways. I noticed then that quote marks from the pasted code snippets were different from the ones on my keyboard (in the snippets they leaned to the right, and if I typed them myself they were straight up and down).
I know this sounds nuts and I could hardly believe it myself, but when I retyped my quotes it worked fine.

Adding android: before the attribute solved my problem.

create an XML file inside your project's res/menu/ directory Not in in res folder
&
dont forget to prefix the id attributes.
Try like this:
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/my_location"
android:icon="#drawable/my_location"
android:title="Current location" />
<item android:id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View" />
<item android:id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view" />
</menu>

Some times the XML code might be written correctly so you need to simply cut what you currently have and then delete it from the line numbers then re-paste it and the error should be fixed. If it doesn't then you know your code is wrong. The xml default is to recognize what you have put at first and needs to be removed in order to begin again. Trust me I just spent 3 days on that very problem and did exactly what is said above, good luck.

If you have something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="person" type="com.abc.PersonEntity"/>
</data>
Move your data inside layout tag:
<layout xmlns:android="http://schemas.android.com/apk/res/android" >
<data>
<variable name="person" type="com.abc.PersonEntity"/>
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
...

You've forgotten to prefix the id attributes. Try to do it like this:
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/my_location"
android:icon="#drawable/my_location"
android:title="Current location" />
<item android:id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View" />
<item android:id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view" />
</menu>

there was two error silly error
- id isn't it attribute is android:id
- First itme android:title:= you have written extra colon after title
here is implemented code
<?xml version="1.0" encoding= "utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/my_location"
android:icon="#drawable/my_location"
android:title="Current location"/>
<item
android:id="#+id/mapview_satellite"
android:icon="#drawable/satelliteview"
android:title="Satellite View"/>
<item
android:id="#+id/mapview_normal"
android:icon="#drawable/normalview"
android:title="Normal view"/>
</menu>

Related

getActionView() of my MenuItem return null in AppCompat

I had this menu xml that works fine:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="#+id/context_menu_save"
android:actionViewClass="my.app.TextViewPlus"
android:showAsAction="always"
android:title="#string/logout"
android:visible="false"/>
</menu>
But when i started using AppComap v7 i hade null exception when using getActionView().
I change my menu layout to:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/context_menu_save"
myapp:actionViewClass="my.app.TextViewPlus"
myapp:showAsAction="always"
android:title="#string/logout"
android:visible="false"/>
</menu>
And now it works fine. Can anyone explain, why is it happens?
xmlns:myapp this is used when you create your own (or use others) customized views.
xmlns:android this is used when default android views.
so as ur question, i hope ur using your own (or use others) customized views. so u got error.
In Android Studio v1.5, I see the following message for this scenario:
When using the appcompat library, menu resources should refer to the app: namespace, not the android: namespace.
When not using the appcompat library, you should be using the android: namespace.

Android ActionBar XML attributes issue

I followed the instruction in http://developer.android.com/guide/topics/ui/actionbar.html
to make action bars. Basically, it works for one activity but not the other..
after change XML attribute to 'android' instead of what the developer sugguested 'yourapp' from xmlns:yourapp="http://schemas.android.com/apk/res-auto", it works for the one that failed initially
What is the problem here?
Following are the codes for each menu
This works for OutputPaymentActivity but NOT OutputRefinanceActivity
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:slc="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.simpleloancalculator.OutputPaymentActivity" >
<item
android:id="#+id/email"
slc:showAsAction="ifRoom|withText"
android:icon="#drawable/ic_action_email"
android:title="#string/email"/>
</menu>
vice versa:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.simpleloancalculator.OutputRefinanceActivity" >
<item
android:id="#+id/email"
android:icon="#drawable/ic_action_email"
android:title="#string/email"
android:showAsAction="ifRoom|withText"/>
</menu>
Thank you!
Try to replace with this :
xmlns:slc="http://schemas.android.com/apk/res/com.example.simpleloancalculator"
this value (com.example.simpleloancalculator) replace with your package name.

I have a error while creating an item in my menu?

<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/test"
android:icon="#drawable/ic_lanucherxx.png" // error
android:title="#string/news"
android:showAsAction="ifRoom"/>
<item android:id="#+id/test2"
android:icon="#drawable/we.png" //error
android:title="#string/newss2"
android:showAsAction="ifRoom"/>
here is the xml file . the error says that there are no such images in the drawable folder . But i have made sure that that required images are present in all of those drawables folders .
Thank you for your time .
don't use extension .png
just remove it and try once i hope it solves your problem

Can't access android/drawable Icon-Resource

I'm creating a Optionsmenu, for that I use the Android Icon-Resource. But I can't access them, what am I doing wrong. What do I need to change?
Here's the Code of my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/Videos"
android:icon="#android/drawable/ic_menu_view"
android:title="Videos" />
<item android:id="#+id/Bio"
android:icon="#android/drawable/ic_menu_friendlist"
android:title="Biographie" />
<item android:id="#+id/Support"
android:icon="#android/drawable/ic_menu_star"
android:title="Support" />
</menu>
thank you for the help in advance!
You are almost correct, when accessing framework resources you have to prefix the resource type with android: since you are using the android package here. Which means it should not be
android:icon="#android/drawable/ic_menu_view"
but
android:icon="#android:drawable/ic_menu_view"
instead for example (note the colon between android and drawable instead of a forward slash).
Also note that you can't access some resources, since they are not public, such as the ic_menu_star you are using here. You have to copy them to your projects drawable folders, which means you have to access them via a normal #drawable/ic_menu_star after doing that. See this question for reference.
try :
android:icon="#android:drawable/ic_menu_view"
instead of :
android:icon="#drawable/ic_menu_view"
Try this:
<item android:id="#+id/Videos"
android:icon="#drawable/ic_menu_view"
android:title="Videos" />
<item android:id="#+id/Bio"
android:icon="#drawable/ic_menu_friendlist"
android:title="Biographie" />
<item android:id="#+id/Support"
android:icon="#drawable/ic_menu_star"
android:title="Support" />
I think #android/drawable/ is incorrect. You should use instead #drawable/
You can see it: http://developer.android.com/guide/topics/ui/menus.html
Hope this helps...

ListView With Nine-Patch Item Background Issues

WARNING: The XML in this question is wrong, read the answer before you confuse yourself!
I have been banging my head on the wall for a while now. The following posts have shed light on the subject, but failed to solve my issue: Android ListView State List not showing default item background and ListView item background via custom selector
The proper nine-patch background shows perfectly when I select the list item, but I can not get the default nine-patch background to show initially. It seems to me that I need to set the default item background somehow, but I can't figure out how to do so.
List View:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/shopListHeader"
/>
<ListView
android:id="#+id/shopList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="0px"
android:divider="#FFFFFFFF"
android:listSelector="#drawable/shop_list_selector"
/>
</LinearLayout>
Selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="true">
<!-- the list items are enabled and being pressed -->
<item
android:state_pressed="true"
android:drawable="#drawable/shop_list_item_pressed" />
<item
android:state_selected="true"
android:textColor="#FFFFFFFF" />
</selector>
Background:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="true">
<item
android:state_selected="true"
android:drawable="#android:color/transparent" />
<item
android:drawable="#drawable/shop_list_item" />
</selector>
As you can see, I have dumbed down the examples from the references.
You may also notice that the Background selector isn't being referenced anywhere. I started tossing it in random places (if the app compiled the addition either had no effect or cause a forced close)
I have also made an attempt to stop the color of the text from changing to black and grey when an item is selected but not pressed (can be done by scrolling through the list). Since my background will be black in the center, the text becomes partially invisible when selected. That addition (the last item node in the Selector) does nothing, as far as I can tell.
Does anyone have any thoughts on getting this ridiculously time consuming functionality working?
I was gonna delete this thread, but I can't so I'll see if I can't use this as an example of what not to do :)
First, in the ListView XML: android:listSelector="#drawable/shop_list_selector"
Don't do that!
What I was trying to do here was set the background of the list items and the android:background property didn't work. You may have noticed that the item XML is missing, and that is because it was missing from my head! (I never touched it over the countless hours I was hammering away at this 'issue') So the line android:background="#drawable/shop_list_selector" goes in the item's properties and everything is groovy. (Remember the XML above is very wrong so don't use it!)
...Well except that it doesn't look as good in real life as it did in my head :(
Back to the drawing board!!!
You havent defined a "normal" state, see this example
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/blue"
android:state_pressed="true" />
<item android:color="#color/red"
android:state_selected="true" />
<item android:color="#color/white" />
</selector>
in here white is the "normal" state, in here you can find some documentation about it.
I hope this helps

Categories

Resources