为什么这个"你必须在AndroidManifest.xml中使用configChanges声明AdActivity."

5 android admob

我不知道这个错误是怎么来的,当我尝试这么多次,所以我在stackoverflow中看到了不同的帖子,但我确实得到了解决方案.所以在此之后我发布了这个问题.我有一个2.3.3 Android应用程序,我正在开发,我想添加Admob广告.我的错误:

在此输入图像描述

这是我的java文件>

package com.example.admobtest;

import android.os.Bundle;
import android.app.Activity;

import com.google.ads.*;

public class MainActivity extends Activity {
    private AdView adView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Create the adView
         adView=(AdView) findViewById(R.id.adView);

        // Initiate a generic request to load it with an ad
        adView.loadAd(new AdRequest());
    }

}
Run Code Online (Sandbox Code Playgroud)

和main.xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在图形布局中

无法实例化以下类: - com.google.ads.AdView(Open Class,Show Error Log)有关详细信息,请参阅错误日志("窗口">"显示视图").

最后在AndroidManifest.xml中

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admobtest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.google.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation" />
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

在这里我也尝试这个 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"而不是android:configChanges="keyboard|keyboardHidden|orientation"但没有效果.

我 从exterval jar文件中添加了GoogleAdMobAdsSdk-6.1.0.jar.

Chi*_*rag 1

要解决此问题,您必须将项目构建目标设置为 Android 3.2 或更高版本。

在此链接上查看更多详细信息。

https://developers.google.com/mobile-ads-sdk/docs/(参见 Android 选项卡)