Hi, I was making a native plugin for unity but the code doesn’t work. But I didn’t find something strange with my code. Here is the java code .
And this is how I called it in C# . The public methods is used for the GUI buttons.
jimmya
January 19, 2017, 1:01am
2
line 18 in your C# should probably be: myClass =new AndroidJavaClass("com.test.flash.FlashAndroidPlugin ");
Thanks for the correction jimmya, that was my mistake. But I still can’t called it when I press the button in my android device.
In unity editor I got an error :
NullReferenceException: Object reference not set to an instance of an object
TestAndroidPlugins.FlashOn () (at Assets/Scripts/TestAndroidPlugins.cs:31)
UnityEngine.Events.InvokableCall.Invoke (System.Object[ ] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:153)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[ ] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:630)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[ ] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:765)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()
Please post the updated code (TestAndroidPlugins.cs)
Hi, the code in C# is still the same as I posted above. I still can’t resolved it till now and I have no idea how to solve it.
Assets/Scripts/TestAndroidPlugins.cs:31
This line doesn’t exist in the code you posted
Oh I’m sorry I forgot to explain that. I deleted the commented code and pasted it here to make it look cleaner.
Did you spot something wrong with my java code or how I call the java function in my C# code @liortal ?