Google AdMob error on Android - android

I'm using adMob sdk 4.3.1 for android and am using xml to create the layout as explained here using Eclipse IDE. The problem is that eclipse doesn't recognize the com.google.ads.AdView tag and gives the error error: error parsing XML: unbound prefix. How do I fix this?
EDIT-Here's the code for the layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR,e78b974e6ab65648b52951e69edcb571"
ads:loadAdOnCreate="true"/>
</LinearLayout>

Just add xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" to the layout!

I'm just guessing here, you'll have to post your xml (obviously):
You're missing xmlns:android="http://schemas.android.com/apk/res/android" or you've spelt something wrong.

Related

Why is there a parse error in my android layout XML?

My activity_main.xml layout file indicates an error: error parsing XML: unbound prefix. No idea why - it seems related to the AdView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<-- ERROR HERE - error parsing XML: unbound prefix -->
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-xxxxxx/xxxxxx"
ads:adSize="SMART_BANNER"/>
</LinearLayout>
You forgot to define the ads prefix for the custom attributes (adSize & adUnitId).
Add to the LinearLayout container:
xmlns:ads="http://schemas.android.com/apk/res-auto"
More details here.
You may have forgotten to add this
xmlns:ads="http://schemas.android.com/apk/res-auto"
Have you also included the right library?

Admob “The following classes could not be instantiated: - com.google.ads.AdView” Android XML Issue

Im trying to get the google admob sdk integrated to display ads in an android application writen in xml. Yes I have already made sure that admob jar is checked in order and export under build path!
I realize there are other open questions but none of the answers solved my issue! Im getting no errors, my project.properties is set to target 19 and my manifest has this:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
and I will post my entire main layout page
Please help me guys!
<RelativeLayout 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"
android:background="#000000"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/text_mainmenu"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="[MYIDHERE]"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true" />
</RelativeLayout>
I had the same issue. There are some issues with the Graphical Layout when you are rendering layouts in Eclipse for Android-19 (KitKat). You cannot change items in the Properties window for example.
Switching to Android-18 in Graphical Layout (green Android top-right) solved the problem for me.

Admob not showing in webview

My ads are not showing, i'm trying to add them in my webview application. This is the main.xml code:
<?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="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14f3ed10a5e4eb"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
Any suggestion??
you have to give the Specific ID to the addMob. Just see the Default Example on GoogleAddMob site and follow that.
Use debug mode via Eclipse and launch and Sample Ad app from the developer.android.com. In LogCat search for "To get test" with Ctrl+F and you will see the id there.
Or check this link with detailed how to:
Get ad id how to

Problems getting adMob setup

I have a very basic android activity with just the following xml code, and permissions to access internet/network state in my manifest, but im still getting the following error:
09-20 15:58:00.896: WARN/Ads(748): Invalid adSize parameter in XML layout: -1. Defaulting to BANNER.
09-20 15:58:00.906: ERROR/Ads(748): AdView missing required XML attribute adUnitId.
heres my xml:
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14e7524ca3db03"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
Take a look at my question a while ago: AdMob: Missing required XML attribute adUnitID
I found out that the correct line should be:
xmlns:ads="http://schemas.android.com/apk/res/com.niek.runningapp"
So try something similar for your app.

com.admob.android.ads.AdView unbound prefix?

I tried to include admob to an Android app in Eclipse. But I get an error in the layout.xml. Eclipse tells me that com.admot.android.ads.AdView is an unbound prefix. I have the admob library included in the build path, following the pdf instruction. But it still does not seem to find the AdView class. But why?
Here is the layout producing the error:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<renegrothmann.kalah.GameView
android:id="#+id/gameView" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="2px"
/>
<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"
/>
</LinearLayout>
I had the same error wit this layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/topLayout"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14df07c16f171a"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Then I made it:
<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/topLayout"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14df07c16f171a"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Notice the second xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" in my RelativeLayout in the second example?
In fact if you remove the android namespace declaration xmlns:android="http://schemas.android.com/apk/res/android" it will start moaning about all the android components too.
Change the following
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
by
<LinearLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
For me it's working with
<TableLayout
android:id="#+id/resultsuperlotto"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" />
Cheers!
Actually, you do not need to add xmlns:ads to a root element (or a parent element).
You can simply add xmlns:ads property to your AdView element, like:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
...>
</com.google.android.gms.ads.AdView>
Check this page.
Maybe you should replace "myapp" at the bottom with "app" or replace "xmlns:app" at the top with "xmlns:myapp". They should probably be the same.
I cannot provide a real answer, since actually I do not know, why it works now. What I did: I restarted with a fresh project. Sometimes, you simply go one wrong step!
Right Click your project, click Properties, click Android, on the Library panel click Add Button
and add both google-play-services_lib and appcompat_v7 libraries
Apply, Refresh, Clean under the Project.
If this doesn't work try the following:
Change the target line in project.properties as target=android-13
Right click on your project and Click Refresh
Click Clean under Project
Hope this will work.

Categories

Resources