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?
NewStringUTFdoesn’t return ajchar; it returns ajstring, which is really just a synonym forjobject.You should change
jchar reg_chaltojstring reg_chal, and changejchar aidtojstring aid.