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

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

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.

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

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"

Add an AdMob Ad above a TabbedView?

I am getting an "Error parsing XML file: Unbound prefix" when I try to put my AdMob ad reference above a tabbed view. Any ideas how to fix that?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_width="fill_parent" android:layout_height="wrap_content"
myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
You're using this:
myapp:backgroundColor
but I don't see any declaration of the 'myapp' prefix. so that might be the source of the error.
Just like the "android" namespace is declared in the xml like this:
xmlns:android="http://schemas.android.com/apk/res/android"
the 'myapp' namespace should have a declaration somewhere also
This answer seems related.
You need both the xmlns set correctly, as Nanne said, as well as your attributes defined in res/style/attrs.xml.
The xmlns appears to be:
xmlns:admob="http://schemas.android.com/apk/res/com.example.package"
For an example attrs.xml, check out the answer above.

Categories

Resources