NullPointer Exception on Unity Ads

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

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

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 .

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?

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);

Yes it was just for example. And I am using Advertisement.Initialize("1001’, false);