5

これを何度も試してみると、このエラーがどのように発生するのかわかりません。この後、この問題を投稿します。Admob 広告を追加したい開発中の 2.3.3 Android アプリがあります。私のエラー:

ここに画像の説明を入力

ここに私の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 に答える