Android 录制和播放音频时出错

Android 录制和播放音频时出错,android,voice-recording,Android,Voice Recording,我用下面的例子来练习 我在这些方面有以下错误 while (isRecording) { // grab the buffered input (mic) and write it to a file on the SD int bufferReadResult = audioRecord.read(buffer, 0, bufferSize); for (int i = 0; i< bufferReadResult; i++) { dos.writ

我用下面的例子来练习

我在这些方面有以下错误

while (isRecording) {
    // grab the buffered input (mic) and write it to a file on the SD
    int bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
    for (int i = 0; i< bufferReadResult; i++) {
    dos.writeShort(buffer[i]);
}

它的力很近,我的logcat

<i>

10-13 12:32:06.710: ERROR/AndroidRuntime(1615): FATAL EXCEPTION: main
10-13 12:32:06.710: ERROR/AndroidRuntime(1615): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voicemodulation/com.voicemodulation.Voicemodulation}: java.lang.ClassCastException: android.widget.Button
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.os.Looper.loop(Looper.java:123)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.main(ActivityThread.java:3647)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at java.lang.reflect.Method.invokeNative(Native Method)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at java.lang.reflect.Method.invoke(Method.java:507)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at dalvik.system.NativeStart.main(Native Method)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615): Caused by: java.lang.ClassCastException: android.widget.Button
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at com.voicemodulation.Voicemodulation.onCreate(Voicemodulation.java:35)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
10-13 12:32:06.710: ERROR/AndroidRuntime(1615):     ... 11 more
10-13 12:32:06.731: WARN/ActivityManager(60):   Force finishing activity com.voicemodulation/.Voicemodulation
10-13 12:32:07.249: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{40731828 com.voicemodulation/.Voicemodulation}
10-13 12:32:15.125: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
10-13 12:32:16.305: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{40731828 com.voicemodulation/.Voicemodulation}
10-13 12:32:17.266: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{4060ebb8 com.example.calldemo/.Calldemo}
10-13 12:32:26.358: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{40731828 com.voicemodulation/.Voicemodulation}
</i>

10-13 12:32:06.710:错误/AndroidRuntime(1615):致命异常:主
10-13 12:32:06.710:错误/AndroidRuntime(1615):java.lang.RuntimeException:无法启动活动组件信息{com.voicemodulation/com.voicemodulation.voicemodulation}:java.lang.ClassCastException:android.widget.Button
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.os.Handler.dispatchMessage(Handler.java:99)上
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.os.Looper.loop(Looper.java:123)上
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):位于android.app.ActivityThread.main(ActivityThread.java:3647)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):位于java.lang.reflect.Method.invokenactive(本机方法)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):位于java.lang.reflect.Method.invoke(Method.java:507)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在dalvik.system.NativeStart.main(本机方法)
10-13 12:32:06.710:错误/AndroidRuntime(1615):由以下原因引起:java.lang.ClassCastException:android.widget.Button
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):位于com.voicemodulation.voicemodulation.onCreate(voicemodulation.java:35)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-13 12:32:06.710:ERROR/AndroidRuntime(1615):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
10-13 12:32:06.710:错误/AndroidRuntime(1615):。。。还有11个
10-13 12:32:06.731:WARN/ActivityManager(60):强制完成活动com.voicemodulation/.voicemodulation
10-13 12:32:07.249:WARN/ActivityManager(60):历史记录{40731828 com.voicemodulation/.voicemodulation}的活动暂停超时
10-13 12:32:15.125:警告/活动管理器(60):启动超时已过期,放弃唤醒锁定!
10-13 12:32:16.305:WARN/ActivityManager(60):历史记录{40731828 com.voicemodulation/.voicemodulation}的活动空闲超时
10-13 12:32:17.266:WARN/ActivityManager(60):历史记录{4060ebb8 com.example.calldemo/.calldemo}的活动空闲超时
10-13 12:32:26.358:WARN/ActivityManager(60):历史记录{40731828 com.voicemodulation/.voicemodulation}的活动销毁超时

<是小于符号“问题似乎是由于此行中的某些ClassCastException

10-13 12:32:06.710: ERROR/AndroidRuntime(1615): Caused by: java.lang.ClassCastException: android.widget.Button
也许你试图对一个小部件进行错误的分类。检查语法

例如

  Button b=(Button)findviewbyId(R.id.button);
可能被错误地初始化为

  Button b=(TextView)findviewbyId(R.id.button);

请显示您的logcat错误。这是'lt'和'bufferSize'变量中的编译错误。非常感谢Sujit。现在它已被更正。但现在它强制关闭我认为缺少一些权限。我还添加了此命令。,
  Button b=(TextView)findviewbyId(R.id.button);