android – Namespace 'ads' not bound-ThrowExceptions

Exception or error:

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>
How to solve:

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

###

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>

###

a name space should be added to your xml root element 😀

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.

###

Add this line of code to your root element

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

Leave a Reply

Your email address will not be published. Required fields are marked *