gee*_*eta 0 java-native-interface android android-ndk
我想在Android上使用JNI调用非静态方法.我可以使用调用静态方法 CallStaticVoidMethod.为了调用非静态方法,我已经使用过了CallVoidMethod.它不起作用.
任何人都可以告诉我正确的代码从JNI调用Android的非静态方法?
jmethodID method = env->GetMethodID(gJniRefCached.ImsFwkLoaderClass, "DispVideo", "([BII)V");
Run Code Online (Sandbox Code Playgroud)
env-> CallVoidMethod(gJniRefCached.ImsFwkLoaderClass,method,arr,width,height);
我也尝试过使用代码类的对象
jclass cls = env->GetObjectClass(obj);
jmethodID method = env->GetMethodID(cls, "DispVideo", "([BII)V");
env->CallVoidMethod(cls, method,arr,width,height);
为了调用实例方法,您需要提供方法所属的类的实例,表示为jobject.但是,在这两个示例中,您都尝试使用类定义的实例调用实例方法,表示为a jclass.
请尝试以下方法:
jclass cls = env->GetObjectClass(obj);
jmethodID method = env->GetMethodID(cls, "DispVideo", "([BII)V");
env->CallVoidMethod(obj, method, arr, width, height);
Run Code Online (Sandbox Code Playgroud)
请注意第三行代码中的细微差别,我将其obj用作第一个参数,而不是cls.
您还可以在实例方法JNI函数的文档页面上看到这种差异:http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html#wp16656
看看两者GetMethodID并且Call<type>Method- 一个需要jclass,另一个需要jobject.
| 归档时间: |
|
| 查看次数: |
8272 次 |
| 最近记录: |