Android Question Error ClassCastException in CheckConsentAndAddAds

angel_

Well-Known Member
Licensed User
Longtime User
I have this error from Crashlytics

Fatal Exception: java.lang.ClassCastException
java.lang.Integer cannot be cast to java.lang.String
android.app.SharedPreferencesImpl.getString (SharedPreferencesImpl.java:283)

anywheresoftware.b4a.admobwrapper.AdViewWrapper$MobileAdsWrapper.Initialize (AdViewWrapper.java:249)
com.xlingenieria.unifilar.b4xmainpage$ResumableSub_CheckConsentAndAddAds.resume (b4xmainpage.java:2937)
com.xlingenieria.unifilar.b4xmainpage._vvvvvvvvvvvvvvvvvvvvvvvvvvv4 (b4xmainpage.java:2912)
com.xlingenieria.unifilar.b4xmainpage$ResumableSub_B4XPage_Created.resume (b4xmainpage.java:2246)
com.xlingenieria.unifilar.b4xmainpage._b4xpage_created (b4xmainpage.java:2127)
...

B4X:
Private Sub CheckConsentAndAddAds
    Dim m As MobileAds
    Wait For (m.Initialize) MobileAds_Ready
'    m.SetConfiguration(m.CreateRequestConfigurationBuilder(Array("94BEBAAE1A9C9C6B3928ED3DE75C7370"))) 'optional. Array with test device ids. See unfiltered logs to find correct id.

    If Ads.GetConsentStatus = "UNKNOWN" Or Ads.GetConsentStatus = "REQUIRED" Then
        Wait For (Ads.RequestConsentInformation(False)) Complete (Success As Boolean)
    End If
    If Ads.GetConsentStatus = "REQUIRED" And Ads.GetConsentFormAvailable Then
        Wait For (Ads.ShowConsentForm) Complete (Success As Boolean)
    End If

It corresponds to this line:

B4X:
Wait For (m.Initialize) MobileAds_Ready

Any ideas?
 

asales

Expert
Licensed User
Longtime User
Is this a single report? Looks like a bug in the ads SDK.

You can catch it:
B4X:
Try
Dim m As MobileAds
 Wait For (m.Initialize) MobileAds_Ready
Catch
 Log(LastException)
End Try
Just for information, I check my Crashlytics reports and saw this same error in my apps.

This is new. In my reports it started in this week.

It only happens in Android 10+, in both type of projects (activities and b4xpages).
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Another informations:
- just run my example the error is raised
- the try..catch solves the problem
- update the SDK solves the problem
1710941341900.png
 
Upvote 0
Top