2011-02-11 72 views
26

我想包括AdMob可以在Eclipse的Android應用程序。但是我在layout.xml中遇到錯誤。 Eclipse告訴我,com.admot.android.ads.AdView是一個未綁定的前綴。遵循pdf說明,我在構建路徑中包含admob庫。但它似乎仍然沒有找到AdView類。但爲什麼?com.admob.android.ads.AdView未綁定前綴?

這裏是產生錯誤的佈局:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    > 

      <renegrothmann.kalah.GameView 
       android:id="@+id/gameView" android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_margin="2px" 
       /> 

      <com.admob.android.ads.AdView 
       android:id="@+id/ad" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       myapp:backgroundColor="#000000" 
       myapp:primaryTextColor="#FFFFFF" 
       myapp:secondaryTextColor="#CCCCCC" 
       /> 

</LinearLayout> 
+0

您是否輸入了`com.admot.android.ads.AdView`錯誤?因爲它應該是admob而不是admot – Nanne 2011-02-11 10:49:07

+0

@Nanne:是的,我輸入了那個,所以這個類型是我的。除了添加庫之外,我不知道如何在該AdView視圖中進行綁定。如果有幫助:我按照文檔中的描述導入了庫並添加了內部庫。 – Rene 2011-02-11 14:07:59

回答

0

也許你應該在底部替換「的myapp」與「應用」或替換「的xmlns:應用」在頂部「的xmlns:MYAPP」。他們應該可能是一樣的。

0

我不能提供一個真正的答案,因爲其實我不知道,爲什麼現在的工作。我做了什麼:我重新開始了一個新項目。有時候,你只是走錯了一步!

90

我有同樣的錯誤機智這個佈局

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/topLayout" 
>   
    <!-- Ad Placeholder --> 
    <com.google.ads.AdView  
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adUnitId="a14df07c16f171a" 
     ads:adSize="BANNER" 
     ads:loadAdOnCreate="true" 
    /> 

</RelativeLayout> 

然後我做到了:

<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:layout_height="fill_parent" 
    android:id="@+id/topLayout" 
>   
    <!-- Ad Placeholder --> 
    <com.google.ads.AdView  
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adUnitId="a14df07c16f171a" 
     ads:adSize="BANNER" 
     ads:loadAdOnCreate="true" 
    /> 

</RelativeLayout> 

請注意,在我的RelativeLayout第二xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"在第二個例子嗎?
事實上,如果你刪除了android命名空間聲明xmlns:android="http://schemas.android.com/apk/res/android"將開始呻吟所有的Android組件了。

5

更改以下

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

通過

<LinearLayout 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

對我來說,它的工作與

<TableLayout 
    android:id="@+id/resultsuperlotto" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" /> 

乾杯!

0

右鍵點擊您的項目,單擊屬性,然後在Android,庫面板上單擊添加按鈕 ,並添加兩個的Google Play-services_lib和appcompat_v7庫 應用,刷新項目下的清潔。

如果這不起作用,請嘗試以下操作:在project.properties

  • 改變目標線目標= Android的13
  • 右鍵點擊你的項目,並單擊刷新
  • 單擊清潔項目

希望這會工作。

0

其實,你並不需要添加xmlns:ads的根元素(或父元素)。

可以xmlns:ads屬性只是添加到您的AdView元素,如:

<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    ...> 
</com.google.android.gms.ads.AdView> 

檢查this page

相關問題