开发者

Error in recording and playing audio

开发者 https://www.devze.com 2023-04-12 23:39 出处:网络
i workout with following example in http://androidgenuine.com/?tag=sound-record-android-modify-voice-on-android

i workout with following example in http://androidgenuine.com/?tag=sound-record-android-modify-voice-on-android

I had following error in these

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

and

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

Its force close and my logcat is

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


&lt is the less then symbol "<" which has been converted script-generated html code during posting of tutorial. So you can add "<" in place of &lt.


The problem appears to be because of some ClassCastException here in this line

10-13 12:32:06.710: ERROR/AndroidRuntime(1615): Caused by: java.lang.ClassCastException: android.widget.Button

Maybe you are trying to caste a widget wrongly. Check for the syntax.

For Ex.

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

could have been wrongly initialized as ,

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号