Why show error unexpected namespace prefix xmlns in android? - android

I want to display Google ads in my app but it shows error unexpected namespace prefix xmlns at this tag xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads". If I remove this line then it shows Error parsing XML:unbound prefix. Please help me to identify that where things go wrong. Here is my code.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/background_port"
tools:context=".MainActivity">
<LinearLayout xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a151b801b7c1d6b"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
</LinearLayout>
--------------------
---- More views ----
--------------------
</LinearLayout>

The error removed by CLEANING THE PROJECT
Project menu -> Clean -> Select Proj -> OK

Related

Could someone explain this bit of XML code please?

For android development, we need XML and I have a couple of doubts about the syntax.
Here's sample code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout android:id="#+id/vMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="false"
ads:adUnitId="#string/banner_ad_unit_id"
ads:adSize="BANNER"
/>
</RelativeLayout>
</RelativeLayout>
On line 8, there is a >, could someone explain the significance of that? If I remove it, the editor complains because it seems to be invalid syntax.
Also, on line 12, if I replace the /> with the full closing tage of </RelativeLayout>, it will not work. Why?
Thanks!
The '>' on line 8 closes the first <RelativeLayout node. '/>' is short hand for closing a node that has no children. The last </RelativeLayout> tag closes that first one. You can't replace it with '/>' because it has child nodes in it.

Admob ad showing error in xml

I am stuck in a problem and search alot but could'nt find the solution here is my code
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
app:adSize="BANNER"
app:adUnitId="xxxxxxxxxx" >
</com.google.ads.AdView>
This code show
Error parsing XML:unbound prefix
when i remove app:adUnitId and app:adsize it do not give any error, how can i remove this error?
Your error is typographical, you're setting:
app:adSize="BANNER"
app:adUnitId="xxxxxxxxxx"
But it should be:
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxx"
xmlns:ads="http://schemas.android.com/apk/res-auto"
Add this to your parent tag.
In my case.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:orientation="vertical" >
Hope this will work.

"No resource found" When using <include layout="">

In my project I have created a global header layout global_header.xml and I use it in all of my layout XML files by using <include layout="#layout/global_header.xml">.
I have used this method before, and I am currently using it in this project. My problem is that I have a layout with the following contents:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/global_header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Contents of global_header.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/global_header"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_alignParentTop="true"
android:background="#FFDDDDDD" >
<ImageView
android:id="#+id/global_header_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginTop="5sp"
android:adjustViewBounds="true"
android:src="#drawable/header" />
<View
android:layout_width="fill_parent"
android:layout_height="1sp"
android:layout_alignParentBottom="true"
android:background="#FF000000" />
</RelativeLayout>
And I am getting an error on android:layout_below="#global/header" saying that:
error: Error: No resource found that matches the given name (at 'layout_below' with value '#global/header').
I have used the include in other layouts in the project and it works without a problem, but for whatever reason, this layout file will not load the ID from the header where as all other layouts do.
The project will not build with this error even though I am sure that once running on the device it will find it not a problem, has anyone else had this problem? Is there solution/workaround?
Any and all help is greatly appreciated.
Try this, specify id for include layout and use
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" android:id="#+id/header"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
Hope both xml (main.xml & global_header.xml) is exist in your layout folder within resources.
kindly clean the project and restart your eclipse, it works.
Note# I checked your xmls I didn't got any error.

error: Error parsing XML: unbound prefix in admob

I tried many combination but it showing following error in xml file
error: Error parsing XML: unbound prefix
in <com.google.ads.AdView line, how can i resolve this.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:adUnitId="000000000000000"
myapp:adSize="BANNER"
myapp:refreshInterval="30"
/>
</RelativeLayout>
<ListView
android:id="#+id/list_of_wishes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="2dip"
android:clickable="true" >
</ListView>
</LinearLayout>
I'd like to think that you should be using the ads: instead of myapp:, but I might be wrong. Let me know if this doesn't work for you:
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="000000000000000"
ads:adSize="BANNER"
ads:refreshInterval="30"
/>
The reason for this possibly helping would be the fact that you've set an ads namespace, but not myapp (as seen in this line):
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

AdMob in android "AdView missing required XML attribute 'adSize' "

I am trying to implement AdMob in my Application. But dont know somehow its showing this error and my R.java file is not being generated due to it. I have tried all the ways to solve this problem, like Clean,Build, Build All. But non is working for me.
Following my code snippet in which its showing error "Error in parsing XML: Unbound prefix"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:background="#color/bgcolor">
<LinearLayout
android:id="#+id/Linearlayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="XXX"
ads:refreshInterval="60"/>
</LinearLayout>
Please help me out. I am stuck here :(
Probably a namespace issue. You have to define the namespace.
try adding
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
New Admob SDK (Google Play services) requiried another namespace
xmlns:ads="http://schemas.android.com/apk/res-auto"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:id="#+id/rltvLayoutPromote"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/linearLayoutwebview"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical">
<WebView android:id="#+id/webViewPromote"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="#+id/ad_layout" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_alignParentBottom="true"
android:layout_alignBottom="#+id/home_layout">
<com.google.ads.AdView android:layout_width="wrap_content"
android:layout_height="wrap_content" ads:adUnitId="XXXXXXXXXX"
ads:adSize="BANNER" android:id="#+id/adView" ads:refreshInterval="60" />
<!-- put 3 if not working-->
</LinearLayout>
</RelativeLayout>
and put this lines in manifest.xml file
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />
the above code is working perfectly for me... visit this site for complete reference help forandroid-admobThanks Pragna

Categories

Resources