C++, Java Native Interface (JNI)

In my recent Java Native Interface (JNI) adventures, I have discovered that when calling the JNI function NewObject in C++, you need to cast the variables to their corresponding jni type. I didn’t have to do this when using C and jni.
Example:
C++ struct ABC { double x, double y };

Using C++ create a jni object to pass to java:

jobject createABC( JNIEnv* env, jobject obj )
{
ABC abc;
a.x = 5.2;
a.y = 2.4;

jclass cls = env->FindClass( “ABC” ); // find the java ABC class

jmethodID mid = env->GetMethodID( cls, ““, “(DD)V” );

jobject jabc = env->NewObject( cls, mid, (jdouble)a.x, (jdouble)a.y);

return jabc;
}

Error Doctor 2007 ***Brand New 2007 Version! <br />“id=”BLOGGER_PHOTO_ID_5052354926391138034” /></a></p>

			</div><!-- .entry-content -->
	
		<footer class= Leave a Comment on C++, Java Native Interface (JNI)/ Edit