Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNI: How can i check if jobject is a null object in native c code

JNI: How can i check if jobject is a null object in native c code

like image 450
RahulMohan82 Avatar asked Feb 27 '10 07:02

RahulMohan82


People also ask

What is JNI Jobject?

jobject thiz means the this in java class. Sometimes if you create a static native method like this. void Java_MyClass_method1 (JNIEnv *, jclass); jclass means the class itself. Follow this answer to receive notifications.

What is JNICALL?

JNICALL contains any compiler directives required to ensure that the given function is treated with the proper calling convention.

What is Jclass in JNI?

typedef jobject jclass; In C++, JNI introduces a set of dummy classes to enforce the subtyping relationship. For example: class _jobject {}; class _jclass : public _jobject {}; ...

What is JNIEnv * env?

jobject NewGlobalRef(JNIEnv *env, jobject obj); Creates a new global reference to the object referred to by the obj argument. The obj argument may be a global or local reference.


1 Answers

Since the objects in Java and C code actually use the same memory locations (the object passed to the native code is the same memory reference in both worlds), a simple

if (someJObject == NULL) {} 

in the C code should be just fine I guess. I haven't tested it though :-)

like image 69
David Sauter Avatar answered Sep 29 '22 11:09

David Sauter