为什么我的代码中的指纹相似性不起作用?

时间:2019-05-08 21:19:44

标签: java android musicg

我正在创建一个用于识别声波文件的应用程序,为此,我发现“ Musicg”库是用于此目的的。因此,我只是在项目中编写了一个简单的代码,以查看声音是否相似,但是当我运行该项目时,它崩溃了,然后我发现,当程序进入FingerprintSimilarity = wave.getFingerprintSimilarity(wave1);时,然后它崩溃了,所以有人可以告诉我我在哪里犯了任何错误吗?

这是我的简单代码

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);


    }

它给了我这些错误:

03-24 23:42:41.984 2817-2817 / com.example.fingerprint E / AndroidRuntime:FATAL EXCEPTION:main     流程:com.example.fingerprint,PID:2817     java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.fingerprint / com.example.fingerprint.MainActivity}:java.lang.NullPointerException:尝试调用虚拟方法'int com.musicg.wave.WaveHeader.getSampleRate( )'在空对象引用上         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)         在android.app.ActivityThread.-wrap11(ActivityThread.java)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)         在android.os.Handler.dispatchMessage(Handler.java:102)         在android.os.Looper.loop(Looper.java:148)         在android.app.ActivityThread.main(ActivityThread.java:5417)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)      原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int com.musicg.wave.WaveHeader.getSampleRate()'         在com.musicg.fingerprint.FingerprintManager.extractFingerprint(FingerprintManager.java:69)         在com.musicg.wave.Wave.getFingerprint(Wave.java:329)         在com.musicg.wave.Wave.getFingerprintSimilarity(Wave.java:335)         在com.example.fingerprint.MainActivity.onCreate(MainActivity.java:31)         在android.app.Activity.performCreate(Activity.java:6237)         在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)         在android.app.ActivityThread.-wrap11(ActivityThread.java)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)         在android.os.Handler.dispatchMessage(Handler.java:102)         在android.os.Looper.loop(Looper.java:148)         在android.app.ActivityThread.main(ActivityThread.java:5417)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)         com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

0 个答案:

没有答案