Admob ad showing error in xml - android

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.

Related

I can't use adMob in my App

When I add the code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#F0F8FF"
android:orientation="vertical" >
<ListView
android:id="#+id/lvHienThi"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id" />
it show me :"No resource identifier found for attribute 'adSize' in package '....'"
How can I fix it ? Please help me. Thank you !
Replace /res/ with /lib/ in your custom layout nampespace
xmlns:android="http://schemas.android.com/apk/res/android"
will be
xmlns:yourApp="http://schemas.android.com/apk/lib/com.yourAppPackege.yourClass"
i hope it help :)
instead of
xmlns:ads="http://schemas.android.com/apk/res-auto"
add
xmlns:ads="http://schemas.android.com/apk/res/your.package.name"
replacing "your.package.name" with your actual package name

Error parsing XML: unbound prefix with admob ad

I have a working layout which look like this:
<?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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-xxx/xxx"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, xxx"
ads:loadAdOnCreate="true"/>
</LinearLayout>
now i want to remove the LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-9000079580883391/8483250253"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, 4FBD7E211FFFF7D7"
ads:loadAdOnCreate="true"/>
then i'm facing the error. I know I need to add the xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" but I dont know where
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" add both of these to your Adview
Use both
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads
xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename
like this
<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:layout_height="fill_parent"
android:id="#+id/main_layout">
<com.google.ads.AdView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/adMob"
android:layout_alignParentBottom="true"
ads:adUnitId="YOUR AdMob publisher ID"
ads:adSize="BANNER"/>
</RelativeLayout>

Why show error unexpected namespace prefix xmlns in 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

android layout overlay issue

I am a beginner in android.I made a flash game android app using a webview and integrated admob ad banner but it is overlaying the webview.I need it to appear like this pic http://i46.tinypic.com/2cosrjp.png
this is my code :
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a1513fab869115a"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</RelativeLayout>
add android:layout_below="+id/lay" inside you webView view
<RelativeLayout
android:id="#+id/lay"
android:layout_below="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
add android:layout_alignParentTop="true" in ads view
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="a1513fab869115a"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
Even though RelativeLayout might be the first choice for many use cases, for this simple view I would use a LinearLayout, that's much easier.
i got the oppiste error, i want my app displayed as yours and i cant get it, i got the answer that u want.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="355dp"
android:layout_height="wrap_content"
ads:adUnitId="000000000000000000"
ads:adSize="BANNER"
android:layout_gravity="center_horizontal|bottom" />
<WebView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/tropas"
android:layout_weight="1.01" />
</LinearLayout>
this is my code and display Aadmob on top Not overlaying webview

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"

Categories

Resources