2011-04-10 100 views
9

我是新手,並且無法正常工作。 我已經完成了http://code.google.com/intl/nl-NL/mobile/ads/docs/android/banner_xml.html的陳述。AdMob:缺少所需的XML屬性adUnitID

這是我的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 /值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。

我在做什麼錯?

+0

感謝您分享錯誤信息。我遇到了同樣的問題,這對我有幫助。 – Gonzo 2011-04-11 21:23:13

+0

Niek能否在下面添加您的修復程序作爲答案並標記爲已回答,以幫助其他人進行搜索並找到它。謝謝 – Blundell 2011-04-26 15:48:03

+2

Devs,如果您在xmlns:ads中使用您的項目包,那麼您還需要添加'attrs.xml',如James [here](http://stackoverflow.com/a/5843540/333137)所述。 對於較新的Admob sdk,不再推薦attrs.xml。 只需使用以下命名空間: 'xmlns:ads =「http://schemas.android.com/apk/lib/com.google.ads」' – 2012-01-22 08:49:04

回答

24

任何人仍然可以嘗試xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"