Admob Unable to destroy activity

半城伤御伤魂 提交于 2019-12-10 19:46:00

问题


Although I have not witnessed this on any of my devices which is more frustrating, I have this stack trace coming through from users in the Market,

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)

The application is a game driven by AndEngine GLES1. It utilises the XML approach to configure the adview, e.g., in my main layout,

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

This is the 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>

Implementation in Main Activity, JewelGobblerActivity, which extends 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;
}

And that is about all as regards to Admob, with the exception of the two Ad show routines in my 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);
        }

    }
    });

}

I am using Admob 6.2.1. It works fine on every device I have to hand including SG 1 and 3, Huawei and Archos... all work fine, from the banner and the interstitial Ad displays. Has anyone else had this issue and or managed to solve it? Any help would be greatly appreciated!

Cheers

Steven

来源:https://stackoverflow.com/questions/14654533/admob-unable-to-destroy-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!