27

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>
Rene
  • 3,746
  • 9
  • 29
  • 33
  • Did you type the ` com.admot.android.ads.AdView` error? Because it should be admob instead of admot – Nanne Feb 11 '11 at 10:49
  • @Nanne : Yes, I typed that, so the type is mine. I have no idea how to bind in that AdView view other than adding the library. If it helps: I imported the library and added the internal library as described in the docs. – Rene Feb 11 '11 at 14:07
  • 2
    Rene. You havent included the admob namespace. This is a must, it is not optional. Also I notice you use com.admob.android.ads.Adview tag. Not sure it that is an older tag name or whether there was just a mistake in the documentation that you have. Try com.google.ads.AdView tag instead. Also, see my answer below. – n4rzul Jul 08 '12 at 09:48

6 Answers6

92

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.

n4rzul
  • 4,059
  • 7
  • 45
  • 64
  • Thanks for the tip. I use what in Google's latest document - xmlns:ads="http://schemas.android.com/apk/res-auto". It works too. – Hong Mar 11 '14 at 12:59
5

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!

ghchoi
  • 4,812
  • 4
  • 30
  • 53
Dax
  • 2,185
  • 2
  • 21
  • 20
2

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.

ghchoi
  • 4,812
  • 4
  • 30
  • 53
0

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.

ladybird
  • 1
  • 1
0

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.

Bashar
  • 1
0

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!

Rene
  • 3,746
  • 9
  • 29
  • 33