Dzxyan
July 22, 2015, 11:40am
1
I’m try to write this on example.cs script
void Start()
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
}
it’s always return the error “Exception: JNI: Init’d AndroidJavaClass with null ptr!”;
I’m sure my platform have switch to android and i’m try to build in apk and run also get same error,
im using unity3d 5.1.1
any help for that?
Are you running this code in the editor? you cannot use the AndroidJavaClass or AndroidJavaObject classes while in the editor. These classes rely on actually running on an Android device with a JVM.
1 Like
Dzxyan
July 23, 2015, 2:11am
3
im try in editor and android also
both got same error
Are you sure tge error is thrown by the code you attached?
Also, could you share the APK so i could peek inside ? (In private).
I would like to see if it contains the UnityPlayer class.
Dzxyan
July 23, 2015, 8:48am
5
liortal:
Are you sure tge error is thrown by the code you attached?
Also, could you share the APK so i could peek inside ? (In private).
I would like to see if it contains the UnityPlayer class.
I’m fully follow this instruction but strange got that error
https://blog.nraboy.com/2014/06/creating-an-android-java-plugin-for-unity3d/
Which line fails exactly in your code?
Dzxyan
July 23, 2015, 11:42am
7
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
maybe can say that all define as AndroidJavaClass will fails
Dzxyan
July 24, 2015, 8:40am
8
Problem solves,
my plugin class read wrong class
2 Likes
KeOt777
February 29, 2016, 10:39pm
9
What exactly was the problem? How did you fix your code? I’m having the same problem you are but since you didn’t publish the code correction I have no idea what you did to fix this, care to share?
Thanks!
@KeOt777 what is the code you’re using? can you share it ?
rashedn
February 24, 2017, 11:13pm
11
Exception: JNI: Init’d AndroidJavaClass with null ptr!
UnityEngine.AndroidJavaClass…ctor (IntPtr jclass) (at C:/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:556)
UnityEngine.AndroidJavaObject.get_JavaLangClass () (at C:/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:534)
UnityEngine.AndroidJavaObject.FindClass (System.String name) (at C:/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:525)
UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) (at C:/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:545)
UnityEngine.AndroidJavaClass…ctor (System.String className) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/AndroidJavaBindings.gen.cs:94)
AudienceNetwork.InterstitialAdBridgeAndroid.Create (System.String placementId, AudienceNetwork.InterstitialAd interstitialAd) (at Assets/AudienceNetwork/Library/InterstitialAd.cs:375)
AudienceNetwork.InterstitialAd…ctor (System.String placementId) (at Assets/AudienceNetwork/Library/InterstitialAd.cs:103)
InterstitialAdTest.LoadInterstitial () (at Assets/AudienceNetwork/Samples/InterstitialAdTest.cs:25)
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:634)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[ ] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:769)
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()
im facing this error message when im trying to add and ads for my game and i really cant understand where is the problem
liortal
February 25, 2017, 4:43pm
12
Are you getting this while playing in the editor? you cannot instantiate any AndroidJavaObject or AndroidJavaClass objects in the editor, since they rely on running inside the Java VM (on an actual Android device).
1 Like
This helps run your build in editor but you will lose some functionality which can be tested only on device.
#if UNITY_ANDROID && !UNITY_EDITOR
void Start()
{
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
}
#endif
4 Likes
raj244u
October 21, 2018, 10:01am
14
i am also getting this error.Please help me out.
_plugin = new AndroidJavaClass(“com.unity3d.player.UnityPlayerActivity”);
_activityObject = _plugin.GetStatic(“currentActivity”);
Debug.Log(_activityObject);
_activityObject.Call(“StartPlugin”);
AndroidJavaClass unityPlayer = new AndroidJavaClass(“com.unity3d.player.UnityPlayer”);
I got error on this line in Unity Editor. As explained earlier. I ignore it in Editor and now ads not showing on device. I got same error for Audience Network and Applovin Initialization. So, I need a proper way to solve this. Anybody knows?
Regards.
JNI access is allowed only when running on device.
Just add UNITY_ANDROID macro to avoid the code running when on editor.
Enable Android JNI in “Package Manager” helped me