问题描述
jstring dateString = (jstring)(*env)->GetObjectField(env, stat, idDate);
……然后一切正常。
解决方法
到目前为止,这就是我所拥有的:我传递一个具有2个字段的对象:String和Integer作为参数,并且我想发送信息以在C部分中对其进行处理,这在当时并不重要…我抱怨在jstring声明
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;
}
我想念什么?