Google语音识别开启新活动

时间:2019-06-17 11:57:00

标签: java android speech-recognition google-cloud-speech

你好朋友,我是我在项目中使用google语音识别的Android新手,如果模式匹配它,我就使用了正则表达式来进行下一个活动,这很正常,但是我的问题是,如果模式不匹配,我的应用就会崩溃崩溃了我想在我的应用程序中显示吐司消息的应用程序,以便用户知道如何在我的应用程序中使用语音识别,这是我的代码。

///如果匹配模式,这是我的逻辑,请转到下一个工作正常的

if(useList(array,bookname)&&chapter.contains("chapter")&&chapternumber.matches("[1-9]+")&&verse.contains("verse")
       &&versenumber.matches("[1-9]+")){
           Intent intent = new Intent(MainActivity.this, ALLVERSE.class);
           intent.putExtra("Boooknumber", booknumber);
           intent.putExtra("Bookname", bookname);
           intent.putExtra("Chapternumber", chapternumberindex);
           intent.putExtra("versenumber", vereseno);
           startActivity(intent);

           Toast.makeText(this, "MACTHED", Toast.LENGTH_SHORT).show();
       }


//my else part if not matched instead showing false in toast my app is crashed

    else{
                   Toast.makeText(this, "false", Toast.LENGTH_SHORT).show();
               } 

这是日志错误:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10, result=-1, data=Intent { (has extras) }} to activity {bible.swordof.God/bible.swordof.God.MainActivity}: java.lang.NumberFormatException: Invalid int: "am"
        at android.app.ActivityThread.deliverResults(ActivityThread.java:3714)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3757)
        at android.app.ActivityThread.-wrap16(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5452)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
     Caused by: java.lang.NumberFormatException: Invalid int: "am"

1 个答案:

答案 0 :(得分:0)

日志错误与NumberFormatException一样显示,因此,将您的代码放在try / catch块中,并检查结果可能是应用程序不会崩溃。

相关问题