Android 调用语音模块

真机实验碰到类似的问题:

java.lang.ClassNotFoundException: Didn't find class "com.example.newland.f20190820.MainActivity" 
on path: DexPathList[[zip file "/data/app/com.example.newland.f20190820-WttI4PUDLJVxUiT8Dt5fZg==
/base.apk"],nativeLibraryDirectories=[/data/app/com.example.newland.f20190820-WttI4PUDLJVxUiT8Dt5f
Zg==/lib/arm64, /system/lib64, /vendor/lib64]]
Process: com.example.newland.f20190820, PID: 23865
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newland.f20190820/com.example.newland.f20190820.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.newland.f20190820.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.newland.f20190820-WttI4PUDLJVxUiT8Dt5fZg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.newland.f20190820-WttI4PUDLJVxUiT8Dt5fZg==/lib/arm64, /system/lib64, /vendor/lib64]]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2879)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3073)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1774)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:198)
        at android.app.ActivityThread.main(ActivityThread.java:7055)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.newland.f20190820.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.newland.f20190820-WttI4PUDLJVxUiT8Dt5fZg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.newland.f20190820-WttI4PUDLJVxUiT8Dt5fZg==/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1175)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)

打开AS -> Settings -> Instant Run -> 将Enable Instant Run to hot swap code/resource changes on depoly(default enable)取消勾选,并确认即可

语音播报主要代码:

import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    TextToSpeech textToSpeech;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
		
		//这里要用到内部类并调用自己的对象,所以必须要将声明写在外边
        textToSpeech  = new TextToSpeech(MainActivity.this , new TextToSpeech.OnInitListener() {
            public void onInit(int i) {
                if(i==TextToSpeech.SUCCESS){
                    textToSpeech.speak("你好世界",TextToSpeech.QUEUE_FLUSH,null);
                }else {
                    Log.i("11111","不可用");
                }
            }
        });

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值