java 怎样把char 转变为object,JNI.如何从Jobject获取jstring并将其转换为char *

This is what I have so far:

I pass an object which has 2 fields: String and Integer, as a parameter

and I want to send information to process it in C part, which is not important at this point...

I get complains at jstring declaration

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, staticsitcs, "amount", "I");

jint amount = (*env)->GetDoubleField(env, stat, idNumber);

// Calling C method

jint totalPallets = checkTotalPalletsIn(date, amount);

(*env)->ReleaseStringUTFChars(env, dateString, date);

return totalPallets;

}

What am I missing?

解决方案

jstring dateString = (jstring)(*env)->GetObjectField(env, stat, idDate);

… and after that everything is OK.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值