25

I am trying to add admob to my android app in android studio. I almost there but am getting the error of:

Namespace 'ads' not bound

Here is also my xml with the ad:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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, TEST_DEVICE_ID"
                               ads:loadAdOnCreate="true"/>


    <TextView
        android:id="@+id/beerTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="20sp"
        android:textStyle = "bold"
        android:padding="5dip"
        >
    </TextView>

    <ImageView android:id="@+id/image"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_margin="10dip"/>



    <TableLayout  

    android:id="@+id/tableLayout1"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:layout_gravity="center_horizontal"
    android:shrinkColumns="*"  
    android:stretchColumns="*"> 

   <TableRow
        android:id="@+id/tableStatTitles"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:padding="5dip" >

        <TextView
            android:id="@+id/abvTitle"
            android:text="ABV"
            android:gravity="center" 
            android:textStyle = "bold"
            android:textSize="20sp"
            android:layout_weight="1"

            ></TextView>

        <TextView
            android:id="@+id/IBUTitle"
            android:text="IBU"
            android:gravity="center" 
            android:textStyle = "bold"
            android:textSize="20sp"
            android:layout_weight="1"

            ></TextView>

        <TextView
            android:id="@+id/glassTitle"
            android:text="Glass"
            android:gravity="center" 
            android:textStyle = "bold"
            android:textSize="20sp"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            ></TextView>




        </TableRow>

    <TableRow
        android:id="@+id/tableStat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:padding="5dip" >

        <TextView
            android:id="@+id/abv"
            android:text=""
            android:gravity="center" 
            android:textSize="15sp"
            android:layout_width="wrap_content"
            ></TextView>

        <TextView
            android:id="@+id/IBU"
            android:text=""
            android:gravity="center" 
            android:textSize="15sp"
            android:layout_width="wrap_content"
            ></TextView>

        <TextView
            android:id="@+id/glass"
            android:text=""
            android:gravity="center" 
            android:textSize="15sp"
            android:layout_width="wrap_content"
            ></TextView>


        </TableRow>

    </TableLayout>

    <View
  android:layout_width="1dp"
  android:layout_height="30dp">
</View>

    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Average Rating: "
        android:textStyle = "bold"
        android:textSize="20sp"
        />

    <TextView
        android:id="@+id/beerRating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="20sp"
        />

    </LinearLayout>

    <View
  android:layout_width="1dp"
  android:layout_height="30dp">
</View>

    <Button
        android:id="@+id/buttonBrewery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text=""
        android:onClick="viewBrewery"
        />



    <Button
        android:id="@+id/buttonStyle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text=""
        android:onClick="viewStyle"

        />

    <View
  android:layout_width="1dp"
  android:layout_height="30dp">
</View>

    <TextView
        android:id="@+id/yourPortfolio"
        android:textStyle = "bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="20sp"
        android:text="Your Portfolio:"
        android:padding="5dip"
        ></TextView>

    <LinearLayout 
    android:id="@+id/addBeerLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

        </LinearLayout>

    <TextView
        android:id="@+id/beerDescriptionTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:padding="5dip"
        android:text="Description:"
        android:textSize="20sp"
        android:textStyle="bold" >
</TextView>
    <TextView
        android:id="@+id/beerDescription"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="15sp"
        android:padding="5dip"

        ></TextView>


    <Button
        android:id="@+id/buttonTasteTag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text="Taste Profile"
        android:onClick="viewTasteTags"

        />



</LinearLayout>
</ScrollView>
rmtheis
  • 5,992
  • 12
  • 61
  • 78
Mike
  • 6,751
  • 23
  • 75
  • 132

5 Answers5

47

You have to add this namespace:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Just paste it below the android namespace:

<ScrollView 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" >

Also, keep in mind that since the update 17 of SDK Tools, you can use http://schemas.android.com/apk/res-auto instead of any of a fully qualified namespace+package-name (more info).

So this should also work:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:auto="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • agreed with @NelsonWu ! The first one results in another Runtime Exception [Ad Size and Ad unit id must be set before loadAd is called](http://stackoverflow.com/questions/23337802/ad-size-and-ad-unit-id-must-be-set-before-loadad-is-called) – Somendra Meena May 15 '17 at 10:16
3

I had the same issue, in my case the solution was to put a closing tag, for example:

<com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>
tm81
  • 328
  • 3
  • 6
0

a name space should be added to your xml root element :D

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

add that line to the top tag or element inside your xml file, and you'll be ready to go.

Ayyoub
  • 4,581
  • 2
  • 19
  • 32
0

Adding the following snippet to your root Element

xmlns:ads="http://schemas.android.com/apk/res-auto"

Example

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
-1

Add this line of code to your root element

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Chaudhary Nouman
  • 202
  • 1
  • 4
  • 12
  • 1
    It is already answered in the previous answer. Don't copy and paste the same answer. Post only if you get any error or other alternative way to solve the problem. – abc Mar 11 '18 at 06:56