Hello,everyone.The problem is this, I can call the static function but can not call non-static function.
My Java code:
public class Main extends UnityPlayerActivity {
public static Context mContext;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext=this;
Log.d("Unity", "OnCreate...........");
}
public int nonIntFunc(int a,int b)
{
Log.d("Unity", "Call non IntFunc...........");
return a+b;
}
}
My Unity Code:
void Start () {
Debug.Log("1->start.....");
jc = new AndroidJavaClass("com.panda.easyvr.Main");
jo = jc.GetStatic<AndroidJavaObject>("mContext");
int m = jo.Call<int>("nonIntFunc", new object[] { 3, 2 });
Debug.Log("Call end! ->"+m);
}
debug log message is always show m value is 0.
I have spent several hours, but the problem is still not resolved. Any available information very grateful!
Hello,JFo. when jo = jc.GetStatic(“mContext”); find logcat error message"
Exception: JNI: Init’d AndroidJavaObject with null ptr! ", can you tell me how to modify ? Thank you .
It looks like you’re trying to call nonIntFunc on jo, which is the mContext field, which is a Context object. So that function doesn’t exist. You should be calling it on jc, which is the Main class.
thanks,but logcat show error message“I/Unity ( 1436): AndroidJavaException: java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()”