0

このコードで何が問題になっているのか教えてください。実際には、次のコード行で、jni (C コード) の文字列で sdcard のパスを取得し、ループを使用してこれらを手動で連結する連結関数で使用しています。連結によって返された文字列は正常に機能しますが、それを jstring に変換すると、logcat にガベージ値が出力されます。何が問題なのか教えてください。

 jstring str=(jstring)env->CallObjectMethod(sdcard,storagestring);
    const char    jclass cfile=env->FindClass("java/io/File");
    jmethodID fileid=env->GetMethodID(cfile,"<init>","(Ljava/lang/String;)V");
    jclass envir=env->FindClass("android/os/Environment");
        jmethodID storageid=env->GetStaticMethodID(envir,"getExternalStorageDirectory","()Ljava/io/File;");
        jobject sdcard=env->CallStaticObjectMethod(envir,storageid);
        jclass sdc=env->GetObjectClass(sdcard);
        jmethodID storagestring=env->GetMethodID(sdc,"toString","()Ljava/lang/String;");

         *nativeString = env->GetStringUTFChars(str, 0);
     char *s =concatenate(nativeString,"/f1.3gp");
        //fpath=s;
        fpath=env->NewStringUTF(s);
    jobject fobject=env->NewObject(cfile,fileid,fpath);
    LOGI("size of char=%d size of string=%d",sizeof("/f1.3gp"),sizeof(fpath));
    jmethodID existid=env->GetMethodID(cfile,"exists","()Z");
    if(env->CallBooleanMethod(fobject,existid))
    {
     jmethodID delid=env->GetMethodID(cfile,"delete","()Z");
     if(env->CallBooleanMethod(fobject,delid))
     LOGE("File is deleting...%s",env->NewStringUTF("/f1.3gp"));
    }
    jmethodID newfileid=env->GetMethodID(cfile,"createNewFile","()Z");
    if(env->CallBooleanMethod(fobject,newfileid))
        LOGE("dig dig %s",fpath);
    jthrowable exc=env->ExceptionOccurred();
    if(exc)
    {
     env->ExceptionDescribe();
     env->ExceptionClear();
    }
    LOGE("creating file %s",fpath);
    }
4

0 に答える 0