error using the admobs - java.lang.IllegalStateException android.view.ViewGroup.addViewInner

K

kfir

Guest
I keep getting this report from google play console: java.lang.IllegalStateException

android.view.ViewGroup.addViewInner

java.lang.IllegalStateException:
at android.view.ViewGroup.addViewInner (ViewGroup.java:5034)
at android.view.ViewGroup.addView (ViewGroup.java:4865)
at android.view.ViewGroup.addView (ViewGroup.java:4805)
at android.view.ViewGroup.addView (ViewGroup.java:4778)
at com.google.android.gms.internal.ads.zzcmh.onSuccess (zzcmh.java:17)
at com.google.android.gms.internal.ads.zzdda.run (zzdda.java:13)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at com.google.android.gms.internal.ads.zzdac.zzb (zzdac.java:7)
at com.google.android.gms.internal.ads.zzauf.zzb (zzauf.java:8)
at com.google.android.gms.internal.ads.zzdac.dispatchMessage (zzdac.java:5)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6762)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)


and before:

java.lang.IllegalStateException:
at android.view.ViewGroup.addViewInner (ViewGroup.java:4659)
at android.view.ViewGroup.addView (ViewGroup.java:4495)
at android.view.ViewGroup.addView (ViewGroup.java:4436)
at android.view.ViewGroup.addView (ViewGroup.java:4409)
at com.google.android.gms.internal.ads.zzcmh.onSuccess (zzcmh.java:17)
at com.google.android.gms.internal.ads.zzdda.run (zzdda.java:13)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at com.google.android.gms.internal.ads.zzdac.zzb (zzdac.java:7)
at com.google.android.gms.internal.ads.zzauf.zzb (zzauf.java:8)
at com.google.android.gms.internal.ads.zzdac.dispatchMessage (zzdac.java:5)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:7325)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)


Not sure how to investigate it. - I think it happens when the admobs are loaded oncreate.

This errors started to appear when I started using mediation with unity. I have added Facebook ads also but it is still not available.

any ideas how to fix or prevent it? it doesn't happen on the normal development configuration

This is my code

mAdView = findViewById(R.id.ad_view);

RequestConfiguration conf = MobileAds.getRequestConfiguration().toBuilder()
.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE)
.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE)
.setMaxAdContentRating(MAX_AD_CONTENT_RATING_G)
.build();
MobileAds.setRequestConfiguration(conf);

MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});


AdRequest adRequest = new AdRequest.Builder().build();


mAdView.loadAd(adRequest);


mInterstitialAd = new InterstitialAd(this);

mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxxxx/xxxxxxxxx");

mInterstitialAd.setAdListener(new AdListener()
{
@Override
public void onAdLoaded()
{
//log interstitial loaded
}
@Override
public void onAdFailedToLoad(int errorCode)
{
Log.d(TAG, "onAdFailedToLoad : errorcode : " + String.valueOf(errorCode));
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdClosed()
{

AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
// Ad interstitialAd reLoaded
Log.d(TAG, "Ad interstitialAd reLoaded");
super.onAdClosed();
}
});
mInterstitialAd.loadAd(new AdRequest.Builder().build());

@Override protected void onDestroy() {
super.onDestroy();
try {
if (mAdView != null) {
mAdView.setAdListener(null);
if (adscontainerWait != null)
adscontainerWait.removeAllViews();
mAdView.destroy();

}
mInterstitialAd = null;

} catch (Exception ex) {
Log.d(TAG, ex.toString());
}
}

Continue reading...
 
Top