Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

NullPointer Exception on Unity Ads

Discussion in 'Unity Ads & User Acquisition' started by Reloaded23, Jun 12, 2015.

  1. Reloaded23

    Reloaded23

    Joined:
    Jan 4, 2014
    Posts:
    27
    Hi i am getting NullPointerException in my Unity ads init method.

    Behaviour i saw.
    1. Using unity ads with one id it works fine. Never Gives this exception.
    2. When Used two id for Unity ads i start getting this exception example,

    Both scripts are in my different game objects.

    if (Advertisement.isSupported) {
    Advertisement.allowPrecache = true;
    Advertisement.Initialize (1001);
    } else {
    Debug.Log("Platform not supported");
    }



    if (Advertisement.isSupported) {
    Advertisement.allowPrecache = true;
    Advertisement.Initialize (5000);
    } else {
    Debug.Log("Platform not supported");
    }

    I am trying to use two different ID in my Game as some times ads are finished for the user. to see.


    Is it possible to use two different ID in one Unity Game


    java.lang.Error: FATAL EXCEPTION [main]
    Unity version : 4.5.0f6
    Device model : motorola XT1033
    Device fingerprint: motorola/falcon_asia_ds/falcon_umtsds:5.0.2/LXB22.46-28/30:user/release-keys

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
    at com.unity3d.ads.android.UnityAds.init(UnityAds.java:667)
    at com.unity3d.ads.android.unity3d.UnityAdsUnityWrapper$1.run(UnityAdsUnityWrapper.java:70)
    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:5312)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)


    Please Help
    Thanks
     
  2. Rasmus Selsmark

    Rasmus Selsmark

    Joined:
    Mar 13, 2013
    Posts:
    120
    Hi,

    Short answer is no, it's not possible to initialize ads multiple times from same instance of game. The reason that we don't show more ads in this case, is simply that there is no reason to show same ad to a user, if they have seen it recently.

    We normally only see this in test scenarios however, where you watch many ads over a short period, don't think it should be a problem in real life.

    /Rasmus
     
  3. Reloaded23

    Reloaded23

    Joined:
    Jan 4, 2014
    Posts:
    27
    Thanks Rasmus,

    Now i am not using multiple ads id in my game. However i am getting NullPointerException still.

    As i am showing ads in Multiple Scene, so i am doing like this.

    if (Advertisement.isInitialize && Advertisement.isSupported) {
    Advertisement.allowPrecache = true;
    Advertisement.Initialize (1001);
    } else {
    Debug.Log("Platform not supported");
    }


    I am still getting NullPointerException Can you please help me why this, other wise i have to move to some other ads sdks .



     
  4. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    I don't think that code will even compile since it has typing errors.. and where did you pick 1001? or are you using just as example for forums?
     
  5. rhbrr5hrfgdfgw

    rhbrr5hrfgdfgw

    Joined:
    Jun 15, 2013
    Posts:
    7
    1001 should be string.. and Initialize takes to parameters, the second one is boolean to see if you are testing or not. false if you want the real ads or true if you want a test ad
    Advertisement.Initialize ("1001", false);
     
  6. Reloaded23

    Reloaded23

    Joined:
    Jan 4, 2014
    Posts:
    27
    Yes it was just for example. And I am using Advertisement.Initialize("1001', false);