Admob无法摧毁活动

时间:2013-02-01 20:34:09

标签: android admob andengine

虽然我没有在任何更令人沮丧的设备上看到这一点,但我在市场上的用户中有这个堆栈跟踪,

java.lang.RuntimeException: Unable to destroy activity
sbsoftware.jewelgobbler/com.google.ads.AdActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2676)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2694)
at android.app.ActivityThread.access$2100(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.webkit.WebView.loadUrl(WebView.java:2341)
at android.webkit.WebView.loadUrl(WebView.java:2357)
at a.a(Unknown Source)
at a.a(Unknown Source)
at a.b(Unknown Source)

该应用程序是由AndEngine GLES1驱动的游戏。它利用XML方法配置广告视图,例如,在我的主要布局中,

<?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="fill_parent"
android:layout_height="fill_parent" >
<org.anddev.andengine.opengl.view.RenderSurfaceView
android:id="@+id/xmllayoutRenderSurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:gravity="center" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/xmllayoutRenderSurfaceView"
android:layout_centerInParent="true"
ads:adSize="BANNER"
ads:adUnitId="<MyCode>"
ads:loadAdOnCreate="true" />
</RelativeLayout>

这是Manifest Admob Activity,

<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize| 
smallestScreenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
</application>

在Main Activity中实现,JewelGobblerActivity,它扩展了LayoutGameActivity,

public static AdView adView;
public static InterstitialAd interstitial;

@Override
public void onLoadResources() { 
    adView = (AdView) findViewById(R.id.adView);
    interstitial = new InterstitialAd(this, "<MyCode>");
    AdRequest adRequest = new AdRequest();
    interstitial.loadAd(adRequest);

    //other stuff       
    SceneManager.init(this, mCamera);
    LoadCurrentDetails();

} 
...
@Override
protected int getLayoutID() {
    // TODO Auto-generated method stub
    return R.layout.main;
}


@Override
protected int getRenderSurfaceViewID() {
    // TODO Auto-generated method stub
    return R.id.xmllayoutRenderSurfaceView;
}

关于Admob的全部内容,除了我的SceneManager中的两个广告节目例外,

public static void ShowInterstitialAd()
{
    JewelGobblerActivity.handler.post(new Runnable() {
    @Override
    public void run() {

    if (JewelGobblerActivity.interstitial != null)
    {

        if (JewelGobblerActivity.interstitial.isReady())
        {
            JewelGobblerActivity.interstitial.show();
            JewelGobblerActivity.interstitial.loadAd(new AdRequest()); //request a new ad
        }
    }

    }
});

}

public static void SetAdVisibility(final boolean Visible)
{
    JewelGobblerActivity.handler.post(new Runnable() {
    @Override
    public void run() {

        if (JewelGobblerActivity.adView != null)
        {
            if (Visible) JewelGobblerActivity.adView.setVisibility(View.VISIBLE);
            else JewelGobblerActivity.adView.setVisibility(View.INVISIBLE);
        }

    }
    });

}

我正在使用Admob 6.2.1。它可以在我必须提供的每台设备上正常工作,包括SG 1和3,华为和Archos ...所有工作正常,从横幅广告和插页式广告展示。有没有其他人有这个问题,或设法解决它?任何帮助将不胜感激!

干杯

史蒂芬

0 个答案:

没有答案