java – JNI. How to get jstring from jobobject and convert it to char*
•
Java
This is what I have done so far:
JNIEXPORT jint JNICALL Java_Tier3_NativeMethods_totalPalletsIn( jnienv *env,jclass cls,jobject stat) { jclass staticsitcs = (*env)->GetObjectClass(env,stat); // Here I try to get it using the ID jfieldID idDate = (*env)->GetFieldID(env,staticsitcs,"date","S"); jstring dateString = (jstring)(*env)->GetStringRegion(env,stat,idDate); // Here converting whatever I get in jstring to char* char* date = (*env)->GetStringUTFChars(env,dateString,0); // Getting the 2nd field from the object jfieldID idNumber = (*env)->GetFieldID(env,"amount","I"); jint amount = (*env)->GetDoubleField(env,idNumber); // Calling C method jint totalPallets = checkTotalPalletsIn(date,amount); (*env)->ReleaseStringUTFChars(env,date); return totalPallets; }
What did I miss?
Solution
jstring dateString =(jstring)(* env) – > GetObjectField(env,idDate);
... everything was fine after that
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码