AdMob:缺少必需的XML属性adUnitID

时间:2011-04-10 17:12:51

标签: android admob identifier

我是广告新手,我无法让它发挥作用。 我已经完成了http://code.google.com/intl/nl-NL/mobile/ads/docs/android/banner_xml.html所述的内容。

这是我的main.xml:

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="com.niek.runningapp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFFFFF"
    android:stretchColumns="1">
<!-- more stuff-->
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adUnitId="a14da18492dd1f0"
            ads:adSize="BANNER" />
    </TableRow>
<!-- More stuff -->

这是res / values中的attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="com.google.ads.AdView">
      <attr name="adSize">
          <enum name="BANNER" value="1"/>
          <enum name="IAB_MRECT" value="2"/>
          <enum name="IAB_BANNER" value="3"/>
          <enum name="IAB_LEADERBOARD" value="4"/>
      </attr>
      <attr name="adUnitId" format="string"/>
  </declare-styleable>
</resources>

运行应用程序时出现以下错误:

  

XML布局中的无效adSize参数:-1。违约到BANNER

     

AdView缺少必需的XML属性adUnitId。

我做错了什么?

2 个答案:

答案 0 :(得分:24)

任何仍在努力的人都可以尝试xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

答案 1 :(得分:3)

对于最新的SDK,应遵循以下条件:

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