5

我不知道这个错误是怎么来的,当我尝试了很多次时,所以我在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());
    }

}

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

在图形布局中

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

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

4

2 回答 2

1

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

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

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

于 2012-10-06T07:23:45.293 回答
0

我认为您缺少元数据标签

    <meta-data  android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

我希望这会有所帮助

于 2014-02-11T23:40:44.913 回答