Reputation: 15
I'm creating an application to recognize the sound of two wave files, for doing this I have found that "Musicg" library is used for that purpose. so I just write a simple code into my project to see if the sound are similar or not, but when I run the project it crashes, then I found that when the program comes to fingerprintSimilarity = wave.getFingerprintSimilarity(wave1); then it crashes, so can anyone tell me where did I do any mistakes?
here is my simple code
FingerprintSimilarity fingerprintSimilarity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Wave wave = new Wave("sampledata/cock_a_1.wav");
Wave wave1 = new Wave("sampledata/cock_a_1.wav");
fingerprintSimilarity = wave.getFingerprintSimilarity(wave1);
float score = fingerprintSimilarity.getScore();
float similarity = fingerprintSimilarity.getSimilarity();
Log.d("hi","score :" +score+ "\n Similarity :" + similarity);
}
it gives me these errors:
03-24 23:42:41.984 2817-2817/com.example.fingerprint E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.fingerprint, PID: 2817 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fingerprint/com.example.fingerprint.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.musicg.wave.WaveHeader.getSampleRate()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.musicg.wave.WaveHeader.getSampleRate()' on a null object reference at com.musicg.fingerprint.FingerprintManager.extractFingerprint(FingerprintManager.java:69) at com.musicg.wave.Wave.getFingerprint(Wave.java:329) at com.musicg.wave.Wave.getFingerprintSimilarity(Wave.java:335) at com.example.fingerprint.MainActivity.onCreate(MainActivity.java:31) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Upvotes: 0
Views: 166
Reputation: 23
The Wave() method accepts the "Inputstream" as a parameter and not the file's path. Convert the file's path to an Inpustream type then put it into the wave parameter.
Upvotes: 0