谁能告诉我在这段代码中我出了什么问题。实际上,在下面的代码行中,我在 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);
}