Android Question The ad unit ID must be set on InterstitialAd before show is called.

Filippo

Expert
Licensed User
Hi,

this message comes from Crashlytics Report.
How can it happen?

Fatal Exception: java.lang.IllegalStateException
The ad unit ID must be set on InterstitialAd before show is called.
Fatal Exception: java.lang.IllegalStateException: The ad unit ID must be set on InterstitialAd before show is called.
at com.google.android.gms.internal.ads.zzzb.zzbl(Unknown Source:159)
at com.google.android.gms.internal.ads.zzzb.show(Unknown Source:145)
at com.google.android.gms.ads.InterstitialAd.show(Unknown Source:20)
at anywheresoftware.b4a.admobwrapper.AdViewWrapper$InterstitialAdWrapper.Show(AdViewWrapper.java:339)
at fg.Solitario_free.main._adview1_receivead(main.java:507)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA$2.run(BA.java:365)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:437)
at fg.Solitario_free.main.afterFirstLayout(main.java:108)
at fg.Solitario_free.main.access$000(main.java:17)
at fg.Solitario_free.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5753)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
B4X:
Sub Activity_Create(FirstTime As Boolean)
...
    'Werbung initialisieren
    If Not(Starter.IsProVersion) Then
        'Admob-Interstitial
        AdView1.Initialize("AdView1","ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxxx")
        LoadAd
    End If
...
End Sub

Sub LoadAd
    'Log("LoadAd")
    Dim builder As AdRequestBuilder
    builder.Initialize
    Dim consent As ConsentManager = Starter.consent
    If consent.IsRequestLocationInEeaOrUnknown Then
        If consent.ConsentState = consent.STATE_NON_PERSONALIZED Then
            builder.NonPersonalizedAds
        Else if consent.ConsentState = consent.STATE_UNKNOWN Then
            Return
        End If
    End If
#if not(Release)
    builder.AddTestDevice("xxxxxxxxxxxxxxxx") 'Samsung A5(2017)
#End If
    AdView1.LoadAdWithBuilder(builder)
End Sub

Sub AdView1_ReceiveAd
    'Log("AdView1_ReceiveAd")
    AdView1.Show
End Sub
 

Filippo

Expert
Licensed User
Does it work if you call LoadAd?
Yes, without problems! As always, however, I can not reproduce the error with my test devices.

Are you sure that AdView type is InterstitialAd?
Yes ;)
upload_2018-11-14_15-45-8.png


The error is currently on the following devices:
Gerät
Marke: samsung
Modell: Galaxy J3(2016)
Ausrichtung: Hochformat
Freier RAM: 263.07 MB
Freier Festplattenspeicher: 400.06 MB

Betriebssystem
Version: 5.1.1
Ausrichtung: Hochformat
Rooting durchgeführt: Nein
Gerät
Marke: samsung
Modell: Galaxy Grand Prime
Ausrichtung: Hochformat
Freier RAM: 299.65 MB
Freier Festplattenspeicher: 1.83 GB

Betriebssystem
Version: 5.0.2
Ausrichtung: Hochformat
Rooting durchgeführt: Nein
Gerät
Marke: samsung
Modell: Galaxy S7 Edge
Ausrichtung: Hochformat
Freier RAM: 1.49 GB
Freier Festplattenspeicher: 7.88 GB

Betriebssystem
Version: 8.0.0
Ausrichtung: Hochformat
Rooting durchgeführt: Nein
 

Filippo

Expert
Licensed User
Are you calling LoadAd multiple times?
I call "LoadAd" in 3 different Activity each in "Activity_Create" 1 times.

Make some tests and kill the activity and recreate it while the ad is loaded.
Thanks, I have to try that.
 

Computersmith64

Well-Known Member
Licensed User
Maybe also try using AdView1.Ready before you call AdView1.Show. Maybe there's a slight delay between when ReceiveAd is fired & it's actually ready.

If you're using Firebase Analytics you could log true & false results from AdView1.Ready - that way you can confirm (or not) if sometimes the ad isn't actually ready when ReceiveAd is fired.

- Colin.
 

Filippo

Expert
Licensed User
Maybe also try using AdView1.Ready before you call AdView1.Show. Maybe there's a slight delay between when ReceiveAd is fired & it's actually ready.

If you're using Firebase Analytics you could log true & false results from AdView1.Ready - that way you can confirm (or not) if sometimes the ad isn't actually ready when ReceiveAd is fired.

- Colin.
Thanks for the tip, it looks better now. ;)

B4X:
Sub AdView1_ReceiveAd
    'Log("AdView1_ReceiveAd")
    If AdView1.Ready Then AdView1.Show
End Sub
 
Top