2011-02-11 74 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

相关问题