在添加了 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();
}