Mike Mike - 21 days ago 7
Android Question

Namespace 'ads' not bound

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>

Answer

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