簡體   English   中英

jni將jstring轉換為char

[英]jni converting jstring to char

我必須將jstring轉換為const char。 我嘗試了以下方法。

jint
Java_flacTest_AudioFormatConversion_convertWavToFlac( JNIEnv* env, jobject thiz, jstring *wavefile, jstring *flacfile, jstring *tempfile) {

    const char *wave_file = (*env)->GetStringUTFChars(env, wavefile, 0);
    // use your string
    (*env)->ReleaseStringUTFChars(env, wavefile, wave_file);

    const char *flac_file = (*env)->GetStringUTFChars(env, flacfile, 0);
    // use your string
    (*env)->ReleaseStringUTFChars(env, flacfile, flac_file);

    const char *temp_file = (*env)->GetStringUTFChars(env, tempfile, 0);
    // use your string
    (*env)->ReleaseStringUTFChars(env, tempfile, temp_file);


__android_log_print(ANDROID_LOG_DEBUG,"LOG_TAG","input file path %s\n", wave_file);
__android_log_print(ANDROID_LOG_DEBUG,"LOG_TAG","input file path 2%s\n", flac_file);
__android_log_print(ANDROID_LOG_DEBUG,"LOG_TAG","input file path3 %s\n", temp_file);

當我打印這些值時,所有值都只有temp_file值。 我需要將所有3個字符串都轉換為const char。 我在這里做錯了什么?

調用ReleaseStringUTFChars()后, GetStringUTFChars()返回的指針無效。 聽起來實現似乎恰好正在重新使用所有三個的存儲-我想指針值都是一樣的。

使用這些值,或在釋放它們之前使用strdup()復制字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM