Android Admob导致java.lang.ArrayIndexOutOfBoundsException:长度=0;索引=0

Android Admob导致java.lang.ArrayIndexOutOfBoundsException:长度=0;索引=0,android,admob,google-play-services,Android,Admob,Google Play Services,我在以下函数中获得ArrayIndexOutOfBoundsException异常 private void insertAdMobAd() { // Create an ad. adView = AdmobAdHandler.getTopAdView(this); AdRequest adRequest = AdmobAdHandler.getAdRequest(); if(adView != null && adRequest != null

我在以下函数中获得ArrayIndexOutOfBoundsException异常

private void insertAdMobAd() {
    // Create an ad.
    adView = AdmobAdHandler.getTopAdView(this);
    AdRequest adRequest = AdmobAdHandler.getAdRequest();

    if(adView != null && adRequest != null) {
        // Add the AdView to the view hierarchy. The view will have no size until the ad is loaded.
        adLayout.addView(adView);
        // Start loading the ad in the background.
        adView.loadAd(adRequest);
    }
} 
这是堆栈跟踪

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shakti.mathssolver/com.mathssolver.pstrip.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
   at android.app.ActivityThread.access$800(ActivityThread.java:144)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5146)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
   at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable()
   at com.google.android.gms.internal.au.a()
   at com.google.android.gms.internal.bh.bi()
   at com.google.android.gms.internal.bh.destroy()
   at com.google.android.gms.ads.AdView.destroy()
   at com.mathssolver.pstrip.BaseSampleActivity.insertAdMobAd(BaseSampleActivity.java:225)
   at com.mathssolver.pstrip.BaseSampleActivity.handleTopAdmobAd(BaseSampleActivity.java:199)
   at com.mathssolver.pstrip.MainActivity.onCreate(MainActivity.java:104)
   at android.app.Activity.performCreate(Activity.java:5231)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
   at android.app.ActivityThread.access$800(ActivityThread.java:144)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5146)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
这里需要注意的一点是,我在上述方法中没有AdView.destroy调用。 销毁调用是在以下函数中进行的,但堆栈跟踪在insertAdMobAd方法中显示它

@Override
public void onDestroy() {
    super.onDestroy();
    // TODO: adview null here , leads to crash sometimes
    if(adView != null)
        adView.destroy();
}

第225行是什么?您的stacktrace似乎来自与您发布的代码不同的应用程序版本。