Android JNI 错误:警告:初始化从指针生成整数而不进行强制转换
我是 Android JNI 新手。我正在将 JAVA 对象从我的 java 文件发送到下面给出的 C 代码。我的 jObject 信息包含 java 中的 char[] 值。实际上,我认为我无法将 jObject 转换为 char,因此当我编译此代码时,我收到错误:
警告:初始化从指针生成整数而不进行强制转换
我的 C 文件:
typedef struct {
unsigned char reg_chal[32];
unsigned char aid[32];
} reg_info_t;
JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_reg(JNIEnv *env,jclass obj,jobject info ,jchar details,jchar reg_code)
{
reg_info_t regInfo;
jclass clazz;
jfieldID fid;
jmethodID mid;
jint status =0;
LOGD("NDK:LC: [%s]", "JNI Function call started");
LOGD("NDK:LC: [%s]", details);
LOGD("NDK:LC: [%c]", reg_code);
//GetInfo(entryInfo); // fills in the entryInfo
clazz = (*env)->GetObjectClass(env, info);
if (0 == clazz)
{
printf("GetObjectClass returned 0\n");
return(-1);
}
jchar reg_chal = (*env)->NewStringUTF(env,regInfo.reg_chal);
fid = (*env)->GetFieldID(env,clazz,"reg_chal","Ljava/lang/String;");
(*env)->SetObjectField(env,info,fid,reg_chal);
LOGD("NDK:LC: [%c]", reg_chal);
jchar aid = (*env)->NewStringUTF(env,regInfo.aid );
fid = (*env)->GetFieldID(env,clazz,"aid ","Ljava/lang/String;");
(*env)->SetCharField(env,info,fid,aid );
LOGD("NDK:LC: [%c]", aid);
//reg_step_1(info , details, reg_code);
//status = reg_step_1(info , details, reg_code);
return status;
}
请帮我解决这个转换错误?
I'm new in Android JNI. I'm sending JAVA object from my java file to C code given below. My jObject info contains char[] values in java.Actually i think I'm unable to convert jObject to char and therefore when i compile this code i get the error:
warning: initialization makes integer from pointer without a cast
My C File :
typedef struct {
unsigned char reg_chal[32];
unsigned char aid[32];
} reg_info_t;
JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_reg(JNIEnv *env,jclass obj,jobject info ,jchar details,jchar reg_code)
{
reg_info_t regInfo;
jclass clazz;
jfieldID fid;
jmethodID mid;
jint status =0;
LOGD("NDK:LC: [%s]", "JNI Function call started");
LOGD("NDK:LC: [%s]", details);
LOGD("NDK:LC: [%c]", reg_code);
//GetInfo(entryInfo); // fills in the entryInfo
clazz = (*env)->GetObjectClass(env, info);
if (0 == clazz)
{
printf("GetObjectClass returned 0\n");
return(-1);
}
jchar reg_chal = (*env)->NewStringUTF(env,regInfo.reg_chal);
fid = (*env)->GetFieldID(env,clazz,"reg_chal","Ljava/lang/String;");
(*env)->SetObjectField(env,info,fid,reg_chal);
LOGD("NDK:LC: [%c]", reg_chal);
jchar aid = (*env)->NewStringUTF(env,regInfo.aid );
fid = (*env)->GetFieldID(env,clazz,"aid ","Ljava/lang/String;");
(*env)->SetCharField(env,info,fid,aid );
LOGD("NDK:LC: [%c]", aid);
//reg_step_1(info , details, reg_code);
//status = reg_step_1(info , details, reg_code);
return status;
}
Please help me how to fix this error of conversion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NewStringUTF
不返回jchar
;它返回一个jstring
,它实际上只是jobject
的同义词。您应该将
jchar reg_chal
更改为jstring reg_chal
,并将jchar acid
更改为jstring aid
。NewStringUTF
doesn't return ajchar
; it returns ajstring
, which is really just a synonym forjobject
.You should change
jchar reg_chal
tojstring reg_chal
, and changejchar aid
tojstring aid
.