gpt4 book ai didi

android - 为什么这个 "You must have AdActivity declared in AndroidManifest.xml with configChanges."

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:31 24 4
gpt4 key购买 nike

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

enter image description here

这是我的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());
}

}

和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>

在图形布局中

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.

最后在 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>

在这里我也尝试使用 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 而不是 android:configChanges="keyboard|keyboardHidden|orientation" 但不影响。

然后我从外部 jar 文件添加 GoogleAdMobAdsSdk-6.1.0.jar

最佳答案

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

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

https://developers.google.com/mobile-ads-sdk/docs/ (参见 Android 标签)

关于android - 为什么这个 "You must have AdActivity declared in AndroidManifest.xml with configChanges.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12757676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com