com.google.ads.AdView无法实例化

sid*_*idG 1 xml android admob

我已经使用了admob sdk并添加了外部jar.In xml我指定了

<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>
Run Code Online (Sandbox Code Playgroud)

表现

<activity android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation"/>
Run Code Online (Sandbox Code Playgroud)

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

com.google.ads.AdView - the following class could not be instantiated. 
Run Code Online (Sandbox Code Playgroud)

程序里面显示它

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

Eri*_*lag 5

文档中,您需要在活动中包含其他configChanges(假设您使用的是4.3.1或更高版本):

<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Run Code Online (Sandbox Code Playgroud)

如果遇到无法识别screenSize和smallestScreenSize的问题,则必须编译aganist Android 3.2或更高版本.查看此迁移博客文章,了解有关将4.1.1升级到更新版本的更多信息(同样适用于迁移到6.0.0).

  • 您可能会收到错误,因为无法识别screenSize和smallestScreenSize配置更改.它们仅在API 13中引入,因此您需要将project.properties中的目标设置为android-13或更高版本以针对最近的SDK进行编译.SDK不对<uses-sdk>元素设置任何限制,因此您仍然可以将minSdkVersion和targetSdkVersion设置为您想要的任何内容,并将您的应用程序提供给这些设备. (2认同)