I extend all my classes from a base class SakadiiMono, which contains the following method:
public bool AndroidSendMessage(ANDROID_DATA.AndroidMessageType _messageType, string _messageData, bool _debug)
{
try
{
if (_debug)
{
this.LogError("MessageType: " + _messageType);
this.LogError("Sending message: " + _messageData);
}
if (inAndroid())
{
if (this.jc == null)
{
this.jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
this.jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
}
if (jc == null)
{
this.LogError("jc is null!!");
}
else
{
if (jo == null)
{
this.LogError("jo - currentActivity is null");
}
else
{
jo.Call("OnUnityMessage", _messageType.ToString(), _messageData.ToString());
}
}
return true;
}
else
{
return false;
}
}
catch (System.Exception ex)
{
this.LogError(ex.ToString());
return false;
}
}
This method is called hundereds of time throughout my code, yet in one particular instance it will throw an exception. The only thing that is different is that it’s being called from within a co-routine.
01-02 15:27:11.450: I/Unity(17522): (Filename: D Line: 0)
UnityEngine.AndroidJavaException: java.lang.NullPointerException
at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJNISafe.CallVoidMethod (IntPtr obj, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject._Call (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject.Call (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
at SakadiiMono.AndroidSendMessage (.AndroidMessageType _messageType, System.String _messageData, Boolean _debug) [0x0009a] in D:\Unity\Projects\[xxxxx]\Assets\Scripts\SakadiiMono.cs:88
Is there some special way I need to be calling this function from a coroutine? I’ve tried to Invoke it, but that doesn’t seem to help either.