Ich versuche, Adobob meiner Android-App im Android-Studio hinzuzufügen. Ich bin fast da, bekomme aber den Fehler von:
Namespace 'ads' not bound
Hier ist auch mein xml mit der Anzeige:
<?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>
Sie müssen diesen Namespace hinzufügen:
xmlns:ads="http://schemas.Android.com/apk/lib/com.google.ads"
Fügen Sie es einfach unter den Android-Namespace ein:
<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" >
Beachten Sie außerdem, dass Sie seit dem Update 17 der SDK-Tools http://schemas.Android.com/apk/res-auto
anstelle eines vollständig qualifizierten Namespaces + Paketnamen ( more info ) verwenden können.
Das sollte also auch funktionieren:
<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" >
Ich hatte das gleiche Problem, in meinem Fall bestand die Lösung darin, ein schließendes Tag zu setzen, zum Beispiel:
<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>
zu Ihrem XML-Root-Element sollte ein Namensraum hinzugefügt werden: D
xmlns:ads="http://schemas.Android.com/apk/lib/com.google.ads"
fügen Sie diese Zeile zum obersten Tag oder Element in Ihrer XML-Datei hinzu, und Sie können loslegen.