Search Unity

Unity Monetization java.lang.RuntimeException

Discussion in 'Unity Ads & User Acquisition' started by max1980, Apr 3, 2020.

  1. max1980

    max1980

    Joined:
    Feb 9, 2017
    Posts:
    6
    hello
    i get this java.lang exception error on android when i call unity ads banner :

    java.lang.RuntimeException: Can't create handler inside thread Thread[Thread-109,5,main] that has not called Looper.prepare()
    04-03 12:48:49.181 10430 11000 E Unity : at android.os.Handler.<init>(Handler.java:207)
    04-03 12:48:49.181 10430 11000 E Unity : at android.os.Handler.<init>(Handler.java:119)
    04-03 12:48:49.181 10430 11000 E Unity : at com.unity3d.services.banners.UnityBanners$BannerAdRefreshView.<init>(UnityBanners.java:221)
    04-03 12:48:49.181 10430 11000 E Unity : at com.unity3d.services.banners.UnityBanners._loadBanner(UnityBanners.java:93)
    04-03 12:48:49.181 10430 11000 E Unity : at com.unity3d.services.banners.UnityBanners.loadBanner(UnityBanners.java:169)
    04-03 12:48:49.181 10430 11000 E Unity : at com.unity3d.player.ReflectionHelper.nativeProxyInvoke(Native Method)
    04-03 12:48:49.181 10430 11000 E Unity : at com.unity3d.player.ReflectionHelper.a(Unknown Source:0)
    04-03 12:48:49.181 10430 11000 E Unity : at com.unity3d.player.ReflectionHelper$1.invoke(Unknown Source:24)
    04-03 12:48:49.181 10430 11000 E Unity : at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
    04-03 12:48:49.181 10430 11000 E Unity : at $Proxy12.onAdFailedToLoad(Unknown Source)
    04-03 12:48:49.181 10430 11000 E Unity : at com.google.unity.ads.Banner$3$2.run(Banner.java:180)
    04-03 12:48:49.181 10430 11000 E Unity : at java.lang.Thread.run(Thread.java:919)

    this error only appears when i call unity ads banner first time, if i close the game and reopen it , everything works fine, also if i didn't call the unity ads banner and instead i call other advertisers banner the game works fine without this exception, also i tried to use old version of the unity monetization asset but the same problem, is there any things can help to fix this? thank you

    Unity Monetization : 3.4.4
    Unity Version : 2018.4.14f1
     
  2. max1980

    max1980

    Joined:
    Feb 9, 2017
    Posts:
    6
    no one can help???
     
  3. sbankhead

    sbankhead

    Unity Technologies

    Joined:
    Jul 27, 2014
    Posts:
    97
    Can you share the code you using to reproduce this. Also some more details about your setup since that stacktrace makes it look like your not using a direct integration of UnityAds which is all we would be able to support you on.
     
  4. PiueGunjanAppStudios

    PiueGunjanAppStudios

    Joined:
    Jan 4, 2021
    Posts:
    1
    I am facing the same error. this is my code
    public void ShowUnityBanner()
    {
    StartCoroutine(ShowBannerWhenReady());
    }
    IEnumerator ShowBannerWhenReady()
    {
    Advertisement.Banner.Load();
    while (!Advertisement.IsReady(unityBannerId))
    {
    yield return new WaitForSeconds(0.5f);
    }
    Debug.Log("Banner ready");
    Advertisement.Banner.Show(unityBannerId);
    Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
    }
     
  5. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @PiueGunjanAppStudios

    I'm not sure this is the cause of the issue, but one thing you might try is calling Advertisement.Banner.SetPosition before showing the banner.

    In addition, I would recommend calling Load before Show and using the BannerLoadOptions to make sure a banner ad has been loaded successfully before trying to show it.