首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >com.google.ads.AdView实例化失败

com.google.ads.AdView实例化失败
EN

Stack Overflow用户
提问于 2012-05-04 19:21:27
回答 3查看 10.2K关注 0票数 1

我使用了admob sdk并将其添加为我指定的外部jar.In xml

代码语言:javascript
复制
<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">
<TextView android:id="@+id/headerfield"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<ListView android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<com.google.ads.AdView 
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"    
    ads:adUnitId="Publisher Id"
    ads:loadAdOnCreate="true" />    
</LinearLayout>

清单

代码语言:javascript
复制
<activity android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation"/>

但在图形模式下,它会给我一个错误日志:

代码语言:javascript
复制
com.google.ads.AdView - the following class could not be instantiated. 

在程序内部它的展示

您必须使用configChanges在AndroidManifest.xml中声明AdActivity。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-05-04 23:38:27

documentation中,您需要在活动中包含额外的configChanges (假设您使用的是4.3.1或更高版本):

代码语言:javascript
复制
<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

如果你遇到screenSize和smallestScreenSize不能被识别的问题,你将不得不编译aganist Android3.2或更高版本。有关从4.1.1升级到新版本的更多信息,请查看此migration blog post (同样适用于升级到6.0.0 )。

票数 5
EN

Stack Overflow用户

发布于 2012-05-04 19:26:03

你也导出了AdMob库了吗?

转至“项目属性”>“Java生成路径”>“排序并导出”

检查您的admob.jar旁边的小方框是否已选中;如果未选中,请执行此操作。

票数 2
EN

Stack Overflow用户

发布于 2015-07-01 23:57:03

如果有人还在查看这个线程-检查你渲染视图的API级别是否低于17。对我来说,它在17下起作用。你可以使用图形布局上方的小droid来更改它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10447822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档