I'm integrating Facebook Ads in my app following their official documentation. But when I run my app I get the following exception
java.lang.IllegalStateException: You can't call show() for ad in state LOADING. You can change Integration Error mode by setting AdSettings.setIntegrationErrorMode()
at com.facebook.ads.internal.c.a.a(Unknown Source:122)
at com.facebook.ads.internal.c.f.a(Unknown Source:6)
at com.facebook.ads.InterstitialAd.show(Unknown Source:2)
at tech.grapegames.pdfreader.ui.MainActivity.moveToFragment(MainActivity.java:115)
at tech.grapegames.pdfreader.ui.HomeFragment.onClick(HomeFragment.java:85)
at android.view.View.performClick(View.java:6897)
at android.view.View$PerformClick.run(View.java:26101)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Below is my code
private com.facebook.ads.InterstitialAd fbInterstitialAd;
fbInterstitialAd = new com.facebook.ads.InterstitialAd(this, getString(R.string.fb_interstitial_ad_id));
fbInterstitialAd.loadAd();
and I'm showing it like below
if (fbInterstitialAd.isAdLoaded() && !fbInterstitialAd.isAdInvalidated()) {
fbInterstitialAd.show();//This line causes the crash
This is the dependency that I've added in build.gradle
implementation 'com.facebook.android:audience-network-sdk:5.+'
You are using the wrong dependency. Replace the following dependency:
implementation 'com.facebook.android:audience-network-sdk:5.+'
with
implementation 'com.facebook.android:audience-network-sdk:5.0.1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With