当前位置:   article > 正文

JNI DETECTED ERROR IN APPLICATION: can‘t call void com.example.myjnidemo.LameUtils.setConvertProgres_qt jni detected error in application: jni getmetho

qt jni detected error in application: jni getmethodid called

 

报错如下图所示:

Jni调用代码如下:

  1. void publishJavaProgress(JNIEnv * env, jobject obj, jint progress) {
  2. //1.找到java的LameUtils的class com/example/myjnidemo/
  3. jclass clazz = (*env).FindClass("com/example/myjnidemo/LameUtils");
  4. if (clazz == 0) {
  5. LOGI("can't find clazz");
  6. }
  7. LOGI(" convert progress %d" , progress);
  8. //2 找到class 里面的方法定义
  9. jmethodID methodid = (*env).GetMethodID(clazz, "setConvertProgress","(I)V");
  10. if (methodid == 0) {
  11. LOGI("can't find methodid");
  12. }
  13. LOGI(" find methodid");
  14. //3 .调用方法
  15. (*env).CallVoidMethod(obj, methodid, progress);
  16. env->DeleteLocalRef(clazz);
  17. }

 

java代码如下:

  1. public class LameUtils {
  2. /**
  3. * wav转换成mp3的本地方法
  4. *
  5. * @param wav
  6. * @param mp3
  7. */
  8. public static native void convertmp3(String wav, String mp3);
  9. /**
  10. * 获取LAME的版本信息
  11. *
  12. * @return
  13. */
  14. public static native String getLameVersion();
  15. public void setConvertProgress(int progress) {
  16. //pd.setProgress(progress);
  17. Log.d("ddebug","转换进度为:"+ progress);
  18. }
  19. }

经排查是因为 convertmp3方法是静态方法,而setConvertProgress是非静态方法,所以会报错

修改如下:

 

  1. void publishJavaProgress(JNIEnv * env, jobject obj, jint progress) {
  2. //1.找到java的LameUtils的class com/example/myjnidemo/
  3. jclass clazz = (*env).FindClass("com/example/myjnidemo/LameUtils");
  4. if (clazz == 0) {
  5. LOGI("can't find clazz");
  6. }
  7. LOGI(" convert progress %d" , progress);
  8. //2 找到class 里面的方法定义
  9. jmethodID methodid = (*env).GetStaticMethodID(clazz,"setConvertProgress","(I)V");
  10. if (methodid == 0) {
  11. LOGI("can't find methodid");
  12. }
  13. LOGI(" find methodid");
  14. //3 .调用方法
  15. (*env).CallStaticVoidMethod(clazz, methodid, progress);
  16. env->DeleteLocalRef(clazz);
  17. }

 

  1. public class LameUtils {
  2. /**
  3. * wav转换成mp3的本地方法
  4. *
  5. * @param wav
  6. * @param mp3
  7. */
  8. public static native void convertmp3(String wav, String mp3);
  9. /**
  10. * 获取LAME的版本信息
  11. *
  12. * @return
  13. */
  14. public static native String getLameVersion();
  15. /**
  16. * 设置进度条的进度,提供给C语言调用
  17. *
  18. * @param progress
  19. */
  20. public static void setConvertProgress(int progress) {
  21. //pd.setProgress(progress);
  22. Log.d("ddebug","转换进度为:"+ progress);
  23. }
  24. }

 

 

 

 

 

 

 

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号