我需要从jni访问活动中的boolean或int字段,这不是静态的,但我得到了这个JNI警告并抛出异常
JNI警告:实例fieldID 0x46488338对类Ljava / lang / Class无效; 在Lcom / example / filehandler / FileHandlerActivity; .beginFileOperation:(Ljava / lang / String;)I(GetIntField)
我能够访问静态字段,为什么它无法访问实例字段?
以下是我用于访问Activity中的int字段的JNI代码:
jint Java_com_example_filehandler_FileHandlerActivity_beginFileOperation(JNIEnv *env,jobject obj,jstring path)
{
target=(*env)->GetStringUTFChars(env,path,0);
jclass cls=(*env)->GetObjectClass(env,obj);
//jclass cls=(*env)->FindClass(env,"com/example/filehandler/FileHandlerActivity");
if(cls==NULL)
{
LOG_INFO("jni : class not found");
return 0;
}
jfieldID fid=(*env)->GetFieldID(env,cls,"status","I");
if(fid==NULL)
{
LOG_INFO("jni : field not found");
return 0;
}
else
{
LOG_INFO("jni : field found");
}
sdcard_status=(*env)->GetIntField(env,obj,fid);
LOG_INFO("jni : sdcard status = %d",sdcard_status);
//writeToFile(target);
(*env)->ReleaseStringUTFChars(env,path,target);
return 1;
}