0

アプリに広告を表示するための admob コードを追加しました。エミュレーターでアプリを実行すると、スプラッシュ画面が開き、「残念ながら、アプリが停止しました」と言ってアプリが突然終了します。なぜ表示されているのかわかりません。admob コードを追加する前にうまく機能します。コードも追加しました。これで私を助けてください。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"``
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@drawable/background2" >


    <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:scrollbars="none">
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="60dp"
        android:background="@null"
        android:padding="30dp"
        android:src="@drawable/menu1"
        android:contentDescription="@string/image_desc" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageButton1"
        android:background="@null"
        android:padding="30dp"
        android:src="@drawable/menu2"
        android:contentDescription="@string/image_desc" />

    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageButton2"
        android:background="@null"
        android:padding="30dp"
        android:src="@drawable/menu3"
        android:contentDescription="@string/image_desc" />

    <ImageButton
        android:id="@+id/imageButton4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageButton3"
        android:background="@null"
        android:padding="30dp"
        android:src="@drawable/menu4"
        android:contentDescription="@string/image_desc" />

     <ImageButton
        android:id="@+id/imageButton5"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageButton4"
        android:background="@null"
        android:padding="30dp"
        android:src="@drawable/menu5"
        android:contentDescription="@string/image_desc" />       
     </LinearLayout>
     </ScrollView>
     <com.google.ads.AdView android:id="@+id/adView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      ads:adUnitId="admob id"
      ads:adSize="SMART_BANNER"
      ads:loadAdOnCreate="true"/>
    </RelativeLayout>
4

2 に答える 2

0

あなたのアプリケーションで少なくとも 1 つの問題を見つけることができると思います。admob 仕様に重要なフィールドが 1 つありません。レイアウトにその行を追加する必要があります。

ads:adUnitId="yourunitid"

Yout ユニット ID を取得するには、アプリを Admob サイト ( http://www.admob.com/my_sites/create_site ) に登録する必要があります。

考慮しなければならないもう 1 つのことは、アプリを挿入したばかりの場合、通常、バナーは数時間後にしか表示されないということです。

最後に、レイアウトに次の行を追加することをお勧めします。

ads:testDevices="TEST_EMULATOR"

これで、「テスト」バナーのみをデバイスに送信するようadmobに言っています(これにより、禁止されるリスクが回避されます)

したがって、adView は次のようになります。

それでも問題が解決しない場合は、logcat 出力を追加してください。

于 2013-08-16T06:56:05.640 に答える