广告在加载android时崩溃

时间:2017-03-21 08:45:09

标签: android nullpointerexception ads

我在我的应用程序中有谷歌广告。他们之前工作正常,我添加了Facebook(观众)广告。我做的是当广告facebook广告无法加载我显示谷歌广告。我的广告使用了towork,但直到昨天他们开始崩溃应用程序时出现错误

  java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
                                                                      at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
                                                                      at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source)
                                                                      at com.google.android.gms.internal.zzpx.zzP(Unknown Source)
                                                                      at com.google.android.gms.internal.zzeg.zza(Unknown Source)
                                                                      at com.google.android.gms.internal.zzeg.zzb(Unknown Source)
                                                                      at com.google.android.gms.internal.zzfa.zzS(Unknown Source)
                                                                      at com.google.android.gms.internal.zzfa.zza(Unknown Source)
                                                                      at com.google.android.gms.ads.InterstitialAd.loadAd(Unknown Source)
                                                                      at com.bison.multipurposeapp.fragments.BaseTabLayoutFragment.requestNewInterstitial(BaseTabLayoutFragment.java:127)
                                                                      at com.bison.multipurposeapp.fragments.BaseTabLayoutFragment.loadInterstitial(BaseTabLayoutFragment.java:164)
                                                                      at com.bison.multipurposeapp.fragments.BaseTabLayoutFragment$1.onError(BaseTabLayoutFragment.java:91)
                                                                      at com.facebook.ads.AdView$1.a(Unknown Source)

这是一段代码;

  private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(Constants.ADMOB_TESTING_DEVICE_LENOVO)
                .build();
        mInterstitialAd.loadAd(adRequest);//here the app crashes
    }

1 个答案:

答案 0 :(得分:0)

您好,您正在将空上下文传递给广告请求。如果您使用的是片段而不是传递let parameters: Parameters = ["q" : "{\"value\" : \"50.50\"}", "apiKey": "2ABdhQTy1GAWiwfvsKfJyeZVfrHeloQI"] ),请传递getActivity(

中收到的上下文