jni updating a string

I'm passing a java class to C thru JNI interface.  The java class has a string member that I need to update in C, but the string is not being updated.  I have provided the basic C code below without the error checking (for clarity).  BTW no errors occur in the C code.  The initial value of the string being passed from java is "9999", and the code below *should* change it to "0000".  

JNIEXPORT void JNICALL
Java_VSJava_doChange(JNIEnv* env, jobject objVSJ, jobject objVSP)
{
  jclass    vsParms;
  jfieldID  fidResultCode;
  jstring   tempString;

  vsParms = (*env)->GetObjectClass(env,objVSP);
  fidResultCode = (*env)->GetFieldID(env, vsParms, "respCode", "Ljava/lang/String;")
  tempString = (*env)->NewStringUTF(env, "0000");  // this is the new value
  // update the field.
  (*env)->SetObjectField(env, vsParms, fidResultCode, tempString);  // this does not report an error.

  return;
}



dhenderson12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
It's been a while since I've worked with JNI, so I'm a bit rusty, but try this :


JNIEXPORT void JNICALL
Java_VSJava_doChange(JNIEnv* env, jobject objVSJ, jobject objVSP)
{
  jclass    vsParms;
  jfieldID  fidResultCode;
  jstring   tempString;
 
  vsParms = (*env)->GetObjectClass(env,objVSP);
  fidResultCode = (*env)->GetFieldID(env, vsParms, "respCode", "Ljava/lang/String;")
  tempString = (*env)->NewStringUTF(env, "0000");
 
  (*env)->SetObjectField(env, objVSP, fidResultCode, tempString);      // <--- objVSP instead of vsParms
 
  return;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Infinity08Commented:
Did it work ? If so, may I ask why you gave a B grade ? That usually means that something was missing in the answer ... If so, feel free to ask for clarification.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.