2011-08-25 69 views
4

我試圖在我的應用程序中實現AdMob。但不知道它顯示這個錯誤,我的R.java文件並沒有被生成,因爲它。我嘗試了所有方法來解決這個問題,比如Clean,Build,Build All。但非是爲我工作。 繼我的代碼片段中,其示值誤差「錯誤在解析XML:未綁定前綴」AdMob在android「AdView缺少必需的XML屬性'adSize'」

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:orientation="vertical" 
android:background="@color/bgcolor"> 

<LinearLayout 
android:id="@+id/Linearlayout1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" > 

<com.google.ads.AdView android:id="@+id/adView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         ads:adSize="BANNER" 
         ads:adUnitId="XXX" 
         ads:refreshInterval="60"/> 


</LinearLayout> 

請幫助我。我在這裏停留:(

回答

16

可能是一個命名空間的問題。你必須定義的命名空間。

嘗試添加

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

+0

我嘗試添加上述行,但後來也是其無法正常工作。對於上面的工作,我是否還必須在'res'目錄中創建'lib'文件夾並將AdMob jar複製到它? – YuDroid

+0

後來當我再次重建並清理該項目時,上面的解決方案爲我工作。感謝Eren – YuDroid

+0

還有一件事要做,就是當我在使用'libs'文件夾嘗試上述代碼時,廣告沒有得到顯示。但是當我將它改爲'lib'時,它的工作沒有麻煩。 – YuDroid

3
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" android:id="@+id/rltvLayoutPromote" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:id="@+id/linearLayoutwebview" 
     android:layout_height="wrap_content" android:layout_width="wrap_content" 
     android:orientation="vertical"> 
     <WebView android:id="@+id/webViewPromote" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:fitsSystemWindows="true" /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" 
     android:id="@+id/ad_layout" android:layout_height="wrap_content" 
     android:gravity="bottom" android:layout_alignParentBottom="true" 
     android:layout_alignBottom="@+id/home_layout"> 
     <com.google.ads.AdView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" ads:adUnitId="XXXXXXXXXX" 
      ads:adSize="BANNER" android:id="@+id/adView" ads:refreshInterval="60" /> 
     <!--   put 3 if not working--> 
    </LinearLayout> 
</RelativeLayout> 

,並把此行manifest.xml文件

<uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" /> 

上述代碼對我來說是完美的... v ISIT本網站的完整參考help forandroid-admob
感謝Pragna

+0

我想要做的是如下的小片段。你能檢查它並告訴我我在哪裏做錯了嗎? – YuDroid

+0

因爲我是初學者,所以我不允許添加超出我允許的字符數限制的評論。所以我編輯了我的問題,幷包含更多的代碼 – YuDroid

+0

好的,讓我試試你的代碼 – Android

6

新版AdMob的SDK(谷歌Play服務)requiried另一個命名空間

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