We have been using Mopub for 6 months to monetize our app. We are using a mechanism that if it returns no ad for native ads we request banner ads from the network.
Recently we are seeing a null pointer exception about Banner Ad Error Code. As the network can't load the ad it gives null pointer exception.
The logcat read from the crashlytics :
com.mopub.mobileads.MoPubFullscreen.lambda$preRender$0 (MoPubFullscreen.java:182)
com.mopub.mobileads.-$$Lambda$MoPubFullscreen$3H3zkNFnaPQ4PqCgAa8VbWGmgJs.run (-.java:2)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
MoPub Library : 5.13.0
My Code :
public void onNativeFail(NativeErrorCode errorCode) {
if (errorCode != NativeErrorCode.CONNECTION_ERROR) {
if (errorCode == NativeErrorCode.NETWORK_NO_FILL) {
CreateMoPubBannerAd(frameLayout);
} else {
HandleAds(frameLayout); // Loads local ads created by ourselves
}
}
}
public void CreateMoPubBannerAd(FrameLayout frameLayout) {
if(frameLayout == null)
{ frameLayout = findViewById(R.id.adContainerView_button);}
if(moPubView == null)
{ moPubView = findViewById(R.id.mopub_banner); }
moPubView.setLocalExtras(localExtras);
moPubView.setAdUnitId(getString(R.string.twitter_banner_ad_unit_id));
moPubView.loadAd();
FrameLayout finalFrameLayout = frameLayout;
moPubView.setBannerAdListener(new MoPubView.BannerAdListener() {
@Override
public void onBannerLoaded(@NonNull MoPubView banner) {
if(adappName != null)
adappName.setVisibility(View.GONE);
moPubView.setVisibility(View.VISIBLE);
}
@Override
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
HandleAds(frameLayout); // Loads local ads created by ourselves}
@Override
public void onBannerClicked(MoPubView banner) { }
@Override
public void onBannerExpanded(MoPubView banner) {}
@Override
public void onBannerCollapsed(MoPubView banner) {}
});
}
Thank you for reading this any help is appreciated
This problem still occurs with MoPub SDK 5.13.1. I found that this issue has been tracked here and will be fixed in a future version for your reference. https://github.com/mopub/mopub-android-sdk/issues/413