08-16 20:55:41.769 E/AndroidRuntime(23151): java.lang.NoSuchMethodError: no non-static method "Lcom/example/jniffmpegstaticplay/JNIffPlay
er;.onPrepareFromJNI()"
08-16 20:55:41.769 E/AndroidRuntime(23151): at com.example.jniffmpegstaticplay.JNIffPlayer.native_prepare(Native Method)
08-16 20:55:41.769 E/AndroidRuntime(23151): at com.example.jniffmpegstaticplay.JNIffPlayer.prepare(JNIffPlayer.java:46)
08-16 20:55:41.769 E/AndroidRuntime(23151): at com.example.jniffmpegstaticplay.MainActivity$1.onClick(MainActivity.java:54)
08-16 20:55:41.769 E/AndroidRuntime(23151): at android.view.View.performClick(View.java:7192)
08-16 20:55:41.769 E/AndroidRuntime(23151): at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:111
現(xiàn)象:直接閃退矢赁,日志不多
用adb命令adb shell logcat -v time > D:\logcat.txt
抓取到上面日志
原因:onPrepareFromJNI
方法找不到科汗,檢查路徑發(fā)現(xiàn)沒問題,懷疑是JNI反射調(diào)用Java方法簽名有問題感局。
-
找到出問題的class文件
- cmd窗口查看類的方法簽名:
$ cd 文件路徑
$ javap -s -p JNIffPlayer
得到結(jié)果:
public void prepare();
descriptor: ()V
public void setDataSource(java.lang.String);
descriptor: (Ljava/lang/String;)V
public void onPrepareFromJNI();
descriptor: ()V
# 方法簽名是:()V
public void onProgressFromJNI(int);
descriptor: (I)V
public void onErrorFromJNI(int);
descriptor: (I)V
public void start();
descriptor: ()V
public void setOnPrepareListener(com.example.jniffmpegstaticplay.JNIffPlayer$OnPrepareListener);
descriptor: (Lcom/example/jniffmpegstaticplay/JNIffPlayer$OnPrepareListener;)V
解決:
修改反射方法的簽名: