com.google.ads.AdView无法实例化布局问题

时间:2013-11-17 19:49:54

标签: android android-layout android-fragments admob

我在使用布局整合admob广告时遇到了问题。在布局中,我有地图片段线性和相对布局。我希望我的广告位于应用的顶部或底部。我的布局文件如下所示:          

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="xxx"
    ads:loadAdOnCreate="true"
    android:layout_centerHorizontal="true"/>

<RelativeLayout
    android:id="@+id/searchTextLayout"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="20dip"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_marginTop="1dip"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/button1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="@null"
        android:onClick="geoLocate"
        android:scaleType="fitCenter"
        android:src="@drawable/but" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/button1"
        android:background="@drawable/sback"
        android:hint="Wprowadź swój adres"
        android:padding="8dp"
        android:textColor="@android:color/black" />



</RelativeLayout>

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" />

当我选择图形布局时,我遇到了这个错误:

 The following classes could not be instantiated:
- com.google.ads.AdView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.


java.lang.NoSuchMethodError: com.google.ads.AdSize.createAdSize(Lcom/google/ads/AdSize;Landroid/content/Context;)Lcom/google/ads/AdSize;
    at com.google.ads.AdView.a(SourceFile:161)
    at com.google.ads.AdView.a(SourceFile:352)
    at com.google.ads.AdView.<init>(SourceFile:125)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(    at sun.reflect.NativeConstructorAccessorImpl.newInstance(    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(    at java.lang.reflect.Constructor.newInstance(    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:372)

有人可以帮我解决这个问题吗? PLZ

3 个答案:

答案 0 :(得分:1)

这几乎肯定与com.google.ads.AdView failed to instantiate相同。特别查看Eric对屏幕尺寸的评论。

确保您还在AndroidManifest中声明了AdActivity

<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

答案 1 :(得分:0)

尝试这一点我相信这会有效,将广告视图移动到线性/相对布局的范围内,在您的情况下相对布局。并确保您已相应地编辑了清单文件。我保证会这样做。

答案 2 :(得分:0)

  1. 单击项目名称。
  2. 右键单击以打开模块设置。
  3. 转到选项卡依赖项。
  4. 点击“添加”按钮。
  5. 选择库依赖项。
  6. 选择Play-Services。