Get Strings used in Java from JNI

后端 未结 1 1581
梦毁少年i
梦毁少年i 2021-01-19 03:43

JAVA Code

Here is some part of my code that I have written in JAVA, As you can see this is a class called JC_VerificationC

相关标签:
1条回答
  • 2021-01-19 04:16

    The following code should allow you to access the field enrollmentID. Use the JNI String functions to read/manipulate them.

    // Load the class
    jclass jclass_JCV = env->FindClass(env, "my.package.JC_VerificationCandidate");
    
    jfieldID fid_enrollmentID = env->GetFieldID(env, jclass_JCV, "enrollmentID" , "Ljava/lang/String;");
    
    // Access the first element in the jVerificationCandList array 
    jobject jc_v = env->GetObjectArrayElement(env, jVerificationCandList, 0);
    
    // get reference to the string 
    jstring jstr = (jstring) env->GetObjectField(env, jc_v, enrollmentID);
    
    // Convert jstring to native string
    const char *nativeString = env->GetStringUTFChars(env, jstr, 0);
    
    0 讨论(0)
提交回复
热议问题