【问题标题】:Error in recording and playing audio录制和播放音频时出错
【发布时间】:2012-05-29 20:38:21
【问题描述】:

我在http://androidgenuine.com/?tag=sound-record-android-modify-voice-on-android 中使用以下示例进行锻炼

我有以下错误

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

while (isPlaying) {
    for (int i = 0; i < bufferSize; i++) {
    // write the 'short' buffer blocks to the audiotrack
    try {
       short s = dis.readShort();
       buffer[i] = s;
    } catch (EOFException eofe) {
    isPlaying = false;
}

它的力关闭,我的 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>

【问题讨论】:

  • 请显示您的 logcat 错误。
  • 'lt' 和 'bufferSize' 变量的编译错误。

标签: android voice-recording


【解决方案1】:

&lt 是小于符号“

【讨论】:

  • 非常感谢苏吉特。现在它已得到纠正。但现在它强制关闭我认为缺少一些权限。
  • 我也添加了这个权限。,
【解决方案2】:

问题似乎是因为这一行中的一些 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    相关资源
    最近更新 更多