Android JNI 错误:警告:初始化从指针生成整数而不进行强制转换

发布于 2024-12-04 11:40:18 字数 1453 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-12-11 11:40:18

NewStringUTF 不返回 jchar;它返回一个jstring,它实际上只是jobject的同义词。

您应该将 jchar reg_chal 更改为 jstring reg_chal,并将 jchar acid 更改为 jstring aid

NewStringUTF doesn't return a jchar; it returns a jstring, which is really just a synonym for jobject.

You should change jchar reg_chal to jstring reg_chal, and change jchar aid to jstring aid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文