0

我有添加或忽略广告的AdActivity要求Admob。我正在使用 aTabActivity并且在选项卡内导航的活动保存在ArrayList. 当我导航到选项卡中的第三个活动然后返回时集成广告后,而不是返回上一个活动(在集成广告之前发生),我将退出应用程序。在将活动添加到时,ArrayList我将意图标志设置为FLAG_ACTIVITY_CLEAR_TOP. 您能否告诉我如何克服在第 3 次后按时退出应用程序activity而能够进入第 2 次activity然后进入第 1 次activity

谢谢你。

编辑:

04-10 13:19:32.519: E/AndroidRuntime(1392): FATAL EXCEPTION: main
04-10 13:19:32.519: E/AndroidRuntime(1392): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admob/com.example.admob.activity.MainTabActivity}: java.lang.NullPointerException
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.os.Looper.loop(Looper.java:137)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at java.lang.reflect.Method.invoke(Method.java:511)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at dalvik.system.NativeStart.main(Native Method)
04-10 13:19:32.519: E/AndroidRuntime(1392): Caused by: java.lang.NullPointerException
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.google.ads.AdView.<init>(SourceFile:87)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.google.ads.doubleclick.DfpAdView.<init>(SourceFile:27)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.example.admob.activity.MainTabActivity.onCreate(MainTabActivity.java:80)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.Activity.performCreate(Activity.java:4465)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-10 13:19:32.519: E/AndroidRuntime(1392):     ... 11 more
4

1 回答 1

0

我终于找到了解决方案!问题在于布局。我相应地改变了它并且它起作用了。以下是我的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dip" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <com.google.ads.doubleclick.DfpAdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            ads:adSize="BANNER"
            ads:adUnitId="AD_UNIT_ID"
            ads:loadAdOnCreate="true"
            android:focusable="false" />
    </RelativeLayout>
</FrameLayout>

于 2013-04-16T07:42:23.407 回答