I'm trying to instantiate a Java class from my C++ code. If I try to call my constructor that takes 2 strings, the constructor is located and gets called, but when I try to access the parameters, an exception is thrown. If I call another constructor that takes, say an int, it works fine. Here is a code snipet: (note, error checking removed)
jmethodID mid = env->GetMethodID(cls, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
jobjectArray argsArray = (jobjectArray)env->NewObjectArray(2,
env->FindClass("java/lang/String"),
env->NewStringUTF(""));
const char *names[2] = { "first", "second" };
for( int i=0; i<2; i++)
env->SetObjectArrayElement(argsArray, i, env->NewStringUTF(names));
obj = env->NewObject(cls, mid, argsArray);
So, in my constructor, I print out that I got there, but when I try to print out the first arg, it throws an exception.
Like I said, using primatives as args works. I also tried passing an object array of on item, same problem.
Funny thing, if I do something similar and try calling my "main" with an array of strings, it works.
Can anyone please help?
Thanks,
Alfredo