I am trying to instantiate a new Java object from C++ using the JNI. I've read extensively on the JNI and have compiled and run all the example code in the tutorial.
Now, I'm trying to do something more complicated and am failing miserable. My C++ program is able to initialize VM args and load the Java VM. Next I am attempting to execute the following code segment:
//This statement succeeds, although the pointer returned
//is always 0x00000002 which seems wrong to me.
//This next statement fails (returns NULL). I've tried
//many variations using "myClass" and "<init>" as the
//method name as well as several different signatures,
//specifically the signature I get from javap -s -p myClass
jmethodID mid = jniENV->GetMethodID(cls, "<init>", "()V");
//This next statement I've never made it to
jobject obj = jniENV->NewObject(cls, mid);
Also, I've tested the Java code and it works to my satisfaction. My problem is only that I am unable to load and run it starting from a C++ application.
Any advice would be greatly appreciated.