每当活动开始时,应用程序中的NullPointerException与AdMob

时间:2012-08-03 13:11:06

标签: android admob

我在添加了AdMob的Android应用程序之后遇到了这样的错误,尽管广告显示正常,我想解决它...你能帮忙吗?

08-03 14:47:28.296: E/Ads(3247): An error occurred while destroying an AdWebView:
08-03 14:47:28.296: E/Ads(3247): java.lang.NullPointerException
08-03 14:47:28.296: E/Ads(3247):    at android.webkit.WebView.setWebViewClient(WebView.java:5084)
08-03 14:47:28.296: E/Ads(3247):    at com.google.ads.internal.AdWebView.destroy(SourceFile:252)
08-03 14:47:28.296: E/Ads(3247):    at com.google.ads.internal.c$e.run(SourceFile:191)
08-03 14:47:28.296: E/Ads(3247):    at android.os.Handler.handleCallback(Handler.java:605)
08-03 14:47:28.296: E/Ads(3247):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-03 14:47:28.296: E/Ads(3247):    at android.os.Looper.loop(Looper.java:137)
08-03 14:47:28.296: E/Ads(3247):    at android.app.ActivityThread.main(ActivityThread.java:4514)
08-03 14:47:28.296: E/Ads(3247):    at java.lang.reflect.Method.invokeNative(Native Method)
08-03 14:47:28.296: E/Ads(3247):    at java.lang.reflect.Method.invoke(Method.java:511)
08-03 14:47:28.296: E/Ads(3247):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-03 14:47:28.296: E/Ads(3247):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-03 14:47:28.296: E/Ads(3247):    at dalvik.system.NativeStart.main(Native Method)

我的代码:

在oncreate()中:

      // Create the adView            
      adView = new AdView(this, AdSize.BANNER,
      ADMOB_UNIT_ID);

      // Lookup your LinearLayout assuming it’s been given            // the
      attribute android:id="@+id/mainLayout"          RelativeLayout layout =
      (RelativeLayout) findViewById(R.id.main_relative_layout);

      // Add the adView to it             layout.addView(adView);

      AdRequest adRequest = new AdRequest();

      if (DebugIndicator.DEBUG) {
          adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // Emulator
          adRequest.addTestDevice(deviceid); // Test Android Device
          adRequest.addTestDevice("c16079314a5512f"); // Test Android
                                                      // Device
          adRequest.addTestDevice("2cf3765d"); // Test Android Device
          adRequest.addTestDevice("FC4AA4F51610C2029A55E3E9A323617A");            }

      // Initiate a generic request to load it with an ad
      adView.loadAd(adRequest);

也增加了活动:

@Override
public void onDestroy() {
    if (adView != null) {
        adView.destroy();
    }
    super.onDestroy();
}

1 个答案:

答案 0 :(得分:2)

这是AdMob SDK捕获并记录为错误的Android WebView错误。它应该记录为警告。它不会导致应用崩溃,也不会影响广告重新加载。