JNI: updating a jstring value inside an object function parameter
Hi All.
I have an class with a jstring object.
I pass this object to a function and change the jstring value in
order to return the object with the modifed value.
All of this when I call a C++ DLL function from java code using JNI.
When I did the following for an INT class member I SUCCEEDED. But
with jstring I failed:
----------------------------------------------------------------------------------------------------------
NIEXPORT jint JNICALL
Java_VTS_Client_Package_VTSclient_vtc_1query_1column(JNIEnv * env,
jobject obj, jint pvci, jstring col_name, jint colIx, jobject refObj){
jclass cls = env->GetObjectClass(refObj);
jfieldID strFieldId = env->GetFieldID(cls, "strVar", "Ljava/lang/
String;");
jfieldID intFieldId = env->GetFieldID(cls, "intVar", "I");
env->SetIntField(refObj, intFieldId, 5); //succeeded - refObj
returned with intVar=5
env->SetObjectField(obj, strFieldId, env->NewStringUTF("5"));//failed
= refObj returned with strVar=""
delete [] buf;
env->ReleaseStringUTFChars(col_name, sColName);
return nRet;
}
----------------------------------------------------------------------------------------------------------
This is the object class
public class RefClass {
public short shortVar;
public int intVar;
public String strVar = "";
}
----------------------------------------------------------------------------------------------------------
Any help will be blessed.
Thanks!