I'm trying to create a jobject in C++ by calling the NewObjectA() function using the JNI invocation API. However, I am unsure how I should pass arguments into the constructor. The JNI API documentation states:
jobject NewObjectA(JNIEnv *env, jclass clazz,jmethodID methodID, const jvalue *args);
NewObjectA
Programmers place all arguments that are to be passed to the constructor in an args array of jvalues that immediately follows the methodID argument. NewObjectA() accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.
In my case the constructor requires two java strings passed to it. I have therefore tried the following:
jclass jcls_File = env->FindClass("java/io/File");
jmethodID File_constructor = env->GetMethodID(jcls_File, "<init>","(Ljava/lang/String;Ljava/lang/String;)V");
jstring home = ctojstring(env,"/home/workspace");
jstring filename = ctojstring(env,"mydatafile");
jvalue FileLocationParams[] = {home,filename}; // COMPILE ERROR HERE.
jobject MyDataFile = env->NewObjectA(jcls_File, File_constructor,FileLocationParams);
Where ctojstring is just the following function:
jstring ctojstring(JNIEnv *env,std::string mystring){
return env->NewStringUTF(mystring.c_str());
}
But when I try to compile I get the following error in Eclipse:
error: invalid conversion from ‘jstring {aka _jstring*}’ to ‘jboolean {aka unsigned char}’ [-fpermissive]
Any thoughts on why this is happening?