3

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

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 方法来配置 adview,例如,在我的主布局中,

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

这是清单 Admob 活动,

<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、华为和爱可视……从横幅和插页式广告显示来看,一切正常。有没有其他人遇到过这个问题,或者设法解决了这个问题?任何帮助将不胜感激!

干杯

史蒂文

4

0 回答 0