Hello,
I am trying to implement Facebook Audience Network to my unity project. When I try sample scenes that is provided by sdk, I get an null object reference error.
NullReferenceException: Object reference not set to an instance of an object
AudienceNetwork.AdViewBridgeAndroid.Create (System.String placementId, AudienceNetwork.AdView adView, AudienceNetwork.AdSize size) (at Assets/AudienceNetwork/Library/AdView.cs:470)
AudienceNetwork.AdView..ctor (System.String placementId, AudienceNetwork.AdSize size) (at Assets/AudienceNetwork/Library/AdView.cs:117)
AdViewScene.LoadBanner () (at Assets/AudienceNetwork/Scenes/Banner/AdViewScene.cs:39)
I looked at the line of error and as I understand, object of AndroidJaveObject class can’t be instantiated.
public override int Create(string placementId,
AdView adView,
AdSize size)
{
AdUtility.prepare();
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
if(currentActivity==null){
//CURRENT ACTIVITY IS THE VARIABLE THAT CAUSES ERROR WHILE IT IS NULL
Debug.LogError("No current activity");
}
AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
AndroidJavaObject bridgedAdView = new AndroidJavaObject("com.facebook.ads.AdView",
context,
placementId,
javaAdSizeFromAdSize(size));
AdViewBridgeListenerProxy proxy = new AdViewBridgeListenerProxy(adView, bridgedAdView);
bridgedAdView.Call("setAdListener", proxy);
AdViewContainer adViewContainer = new AdViewContainer(adView);
adViewContainer.bridgedAdView = bridgedAdView;
adViewContainer.listenerProxy = proxy;
int key = AdViewBridgeAndroid.lastKey;
AdViewBridgeAndroid.adViews.Add(key, adViewContainer);
AdViewBridgeAndroid.lastKey++;
return key;
}
Maybe I am missing initialization of a facebook service, but I followed documentation completely.
Do you have any idea about the cause of this error?