Android ICS 4.0 NDK NewStringUTF is crashing down the App

前端 未结 10 1946
长情又很酷
长情又很酷 2020-12-02 15:01

I have a method in JNI C/C++ which takes jstring and returns back jstring some thing like as below,

  NATIVE_CALL(jstring, method)(JNIEnv * env, jobject obj         


        
10条回答
  •  执笔经年
    2020-12-02 15:34

    For me, the solution was to place the content on a const char*:

    const char* string = name_sin.c_str();
    jstring utf8 = env_r->NewStringUTF(string);
    

    and the function:

    jclass cls_Env = env_r->FindClass(CLASS_ACTIVITY_NAME); 
    jmethodID mid = env_r->GetMethodID(cls_Env, "Delegate",
                                     "(Ljava/lang/String;)V");
    
    
    //todo importante hacerlo asi, si pasas directamente c_str a veces da error de carater no UTF 8
    const char* string = name_sin.c_str();
    jstring utf8 = env_r->NewStringUTF(string);
    
    env_r->CallVoidMethod(*object_r, mid, utf8);
    
    env_r->DeleteLocalRef(utf8);
    

提交回复
热议问题