AdMob奖励视频广告错误(例外)

时间:2018-03-24 11:43:37

标签: android exception admob rewardedvideoad

Admob RewardedVideoAd有时不会显示视频。这是第一次显示广告。第二次或第三次,没有显示广告。在这种情况下,我得到这样一个日志:

03-24 13:08:26.754 4458-4458/net.dailytoys.afterthecrash W/Ads: Could not show rewarded video ad from adapter.
                                                                java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.bp hu.a' on a null object reference
                                                                    at com.google.ads.mediation.a.h(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):356)
                                                                    at com.google.android.gms.ads.internal.mediation.client.y.f(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):208)
                                                                    at com.google.android.gms.ads.internal.reward.a.a(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):41)
                                                                    at com.google.android.gms.ads.internal.reward.c.a(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):18)
                                                                    at com.google.android.gms.ads.internal.reward.client.e.onTransact(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):11)
                                                                    at android.os.Binder.transact(Binder.java:388)
                                                                    at com.google.android.gms.internal.zzeu.zzb(Unknown Source)
                                                                    at com.google.android.gms.internal.zzadm.show(Unknown Source)
                                                                    at com.google.android.gms.internal.zzadx.show(Unknown Source)
                                                                    at net.dailytoys.afterthecrash.ActionResolverAndroid$2.run(ActionResolverAndroid.java:86)
                                                                    at android.os.Handler.handleCallback(Handler.java:815)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                    at android.os.Looper.loop(Looper.java:194)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5877)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1015)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
03-24 13:08:26.755 4458-4458/net.dailytoys.afterthecrash W/Ads: Could not call showVideo.
                                                                android.os.RemoteException
                                                                    at com.google.android.gms.ads.internal.mediation.client.y.f(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):212)
                                                                    at com.google.android.gms.ads.internal.reward.a.a(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):41)
                                                                    at com.google.android.gms.ads.internal.reward.c.a(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):18)
                                                                    at com.google.android.gms.ads.internal.reward.client.e.onTransact(com.google.android.gms.DynamiteModulesA@12221246@12.2.21 (246-188803320):11)
                                                                    at android.os.Binder.transact(Binder.java:388)
                                                                    at com.google.android.gms.internal.zzeu.zzb(Unknown Source)
                                                                    at com.google.android.gms.internal.zzadm.show(Unknown Source)
                                                                    at com.google.android.gms.internal.zzadx.show(Unknown Source)
                                                                    at net.dailytoys.afterthecrash.ActionResolverAndroid$2.run(ActionResolverAndroid.java:86)
                                                                    at android.os.Handler.handleCallback(Handler.java:815)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                    at android.os.Looper.loop(Looper.java:194)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5877)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1015)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)

我的初始化方法:

private void initAdMob () {
        MobileAds.initialize(this, AD_MOB_ID);
        mRewardedVideoBonusAd = MobileAds.getRewardedVideoAdInstance(this);
        mRewardedVideoBonusAd.loadAd(ID_REW_BONUS, new AdRequest.Builder().build());

        mRewardedVideoBonusAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
            @Override
            public void onRewardedVideoAdLoaded() {
                System.out.println(adLogPrefix + " rewarded (bonus) loaded.");
            }

            @Override
            public void onRewardedVideoAdClosed() {
                System.out.println(adLogPrefix + " rewarded (bonus) closed.");
                mRewardedVideoBonusAd.loadAd(ID_REW_BONUS, new AdRequest.Builder().build());
            }

            @Override
            public void onRewarded(RewardItem rewardItem) {
                mRewardedVideoBonusAd.loadAd(ID_REW_BONUS, new AdRequest.Builder().build());
            }

            @Override
            public void onRewardedVideoAdFailedToLoad(int i) {
                actionResolverAndroid.logAnalyticEvent(AnalyticsKeys.AD_ERR_LOADING_REW_VIDEO);
                new Handler().postDelayed(
                        new Runnable() {
                            @Override
                            public void run() {
                                mRewardedVideoBonusAd.loadAd(ID_REW_BONUS, new AdRequest.Builder().build());
                            }
                        },
                        1000 * 15 // 15 seconds
                );
                System.out.println(adLogPrefix + " error loading rew (bonus).");
            }
        });
    }

我做了一切,因为它写在官方文档中。可能是什么问题?

1 个答案:

答案 0 :(得分:1)

  

这是AdMob奖励视频的已知问题。

考虑从Rewarded-Callback中删除请求并将其保留在Closed-Callback中,这样你就不会同时拥有它们,并且它们不会相互干扰。

@Override
public void onRewardedVideoAdClosed() {
    System.out.println(adLogPrefix + " rewarded (bonus) closed.");
    // REMOVE THIS LINE BELOW
    mRewardedVideoBonusAd.loadAd(ID_REW_BONUS, new AdRequest.Builder().build());
}

@Override
public void onRewarded(RewardItem rewardItem) {
    mRewardedVideoBonusAd.loadAd(ID_REW_BONUS, new AdRequest.Builder().build());
}