赞
踩
报错如下图所示:
Jni调用代码如下:
- void publishJavaProgress(JNIEnv * env, jobject obj, jint progress) {
- //1.找到java的LameUtils的class com/example/myjnidemo/
- jclass clazz = (*env).FindClass("com/example/myjnidemo/LameUtils");
- if (clazz == 0) {
- LOGI("can't find clazz");
- }
- LOGI(" convert progress %d" , progress);
-
- //2 找到class 里面的方法定义
- jmethodID methodid = (*env).GetMethodID(clazz, "setConvertProgress","(I)V");
- if (methodid == 0) {
- LOGI("can't find methodid");
- }
- LOGI(" find methodid");
-
- //3 .调用方法
- (*env).CallVoidMethod(obj, methodid, progress);
- env->DeleteLocalRef(clazz);
- }
java代码如下:
- public class LameUtils {
- /**
- * wav转换成mp3的本地方法
- *
- * @param wav
- * @param mp3
- */
- public static native void convertmp3(String wav, String mp3);
-
- /**
- * 获取LAME的版本信息
- *
- * @return
- */
- public static native String getLameVersion();
-
-
- public void setConvertProgress(int progress) {
- //pd.setProgress(progress);
- Log.d("ddebug","转换进度为:"+ progress);
- }
-
-
- }
经排查是因为 convertmp3方法是静态方法,而setConvertProgress是非静态方法,所以会报错
修改如下:
- void publishJavaProgress(JNIEnv * env, jobject obj, jint progress) {
- //1.找到java的LameUtils的class com/example/myjnidemo/
- jclass clazz = (*env).FindClass("com/example/myjnidemo/LameUtils");
- if (clazz == 0) {
- LOGI("can't find clazz");
- }
- LOGI(" convert progress %d" , progress);
-
- //2 找到class 里面的方法定义
- jmethodID methodid = (*env).GetStaticMethodID(clazz,"setConvertProgress","(I)V");
- if (methodid == 0) {
- LOGI("can't find methodid");
- }
- LOGI(" find methodid");
-
- //3 .调用方法
- (*env).CallStaticVoidMethod(clazz, methodid, progress);
- env->DeleteLocalRef(clazz);
- }
- public class LameUtils {
- /**
- * wav转换成mp3的本地方法
- *
- * @param wav
- * @param mp3
- */
- public static native void convertmp3(String wav, String mp3);
-
- /**
- * 获取LAME的版本信息
- *
- * @return
- */
- public static native String getLameVersion();
-
- /**
- * 设置进度条的进度,提供给C语言调用
- *
- * @param progress
- */
- public static void setConvertProgress(int progress) {
- //pd.setProgress(progress);
- Log.d("ddebug","转换进度为:"+ progress);
- }
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。