2014-01-20 41 views
1

这是我的代码,我按下停止按钮后应用程序自动关闭。我调试并跟踪到“myAudioRecorder.stop()”,它有“exception(s)_during_the_evaluation”异常。我不知道如何解决它。为什么我触摸停止按钮,不幸关闭我的应用程序

public void stop(View view){ 

    myAudioRecorder.stop(); 
    myAudioRecorder.release(); 
    myAudioRecorder = null; 
    stop.setEnabled(false); 
    play.setEnabled(true); 
    Toast.makeText(getApplicationContext(), "Audio recorded successfully", 
    Toast.LENGTH_LONG).show(); 

} 

logcat的结果

01-20 11:24:22.378: D/GraphicBuffer(28301): create handle(0x5caa3400) (w:480, h:800, f:1) 
01-20 11:24:22.494: I/SurfaceTextureClient(28301): [STC::queueBuffer] (this:0x5ca90e00) fps:0.07, dur:15218.09, max:15218.09, min:15218.09 
01-20 11:24:22.494: I/SurfaceTextureClient(28301): [STC::queueBuffer] this:0x5ca90e00, api:1, last queue time elapsed:15218.09 
01-20 11:24:24.732: V/InputMethodManager(28301): onWindowFocus: null softInputMode=32 first=true flags=#1810100 
01-20 11:24:24.733: V/InputMethodManager(28301): START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{41352438 V.E..... R......D 0,0-480,800} ic=null [email protected] controlFlags=#104 
01-20 11:24:24.745: D/dalvikvm(28301): threadid=11: interp stack at 0x5e1c8000 
01-20 11:24:24.846: V/InputMethodManager(28301): Starting input: Bind result=InputBindResult{null com.vng.inputmethod.labankey/.LatinIME #793} 
01-20 11:24:24.848: D/GraphicBuffer(28301): create handle(0x5dc11f30) (w:480, h:800, f:1) 
01-20 11:24:24.854: I/SurfaceTextureClient(28301): [STC::queueBuffer] (this:0x5ca90e00) fps:0.42, dur:2359.53, max:2359.53, min:2359.53 
01-20 11:24:24.854: I/InputMethodManager(28301): handleMessage: MSG_SET_ACTIVE true, was false 
01-20 11:24:25.595: I/View(28301): Touch down dispatch to android.widget.Button{41382718 VFED..C. ........ 88,448-165,520 #7f080002 app:id/button1}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=42.727646, y[0]=22.317139, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=42646762, downTime=42646762, deviceId=5, source=0x1002 } 
01-20 11:24:25.611: D/GraphicBuffer(28301): create handle(0x5dc14060) (w:480, h:800, f:1) 
01-20 11:24:25.707: I/View(28301): Touch up dispatch to android.widget.Button{41382718 VFED..C. ...P.... 88,448-165,520 #7f080002 app:id/button1}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=42.727646, y[0]=22.317139, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=42646876, downTime=42646762, deviceId=5, source=0x1002 } 
01-20 11:24:25.709: V/Provider/Settings(28301): invalidate [system]: current 175 != cached 0 
01-20 11:24:25.712: D/ActivityThread(28301): installProvider: [email protected][email protected]y=truenoReleaseNeeded=truestable=true 
01-20 11:24:25.713: V/Provider/Settings(28301): from db cache, name = sound_effects_enabled , value = 0 
01-20 11:24:25.723: W/System.err(28301): java.io.FileNotFoundException: /storage/sdcard0/myrecording.3gp: open failed: EACCES (Permission denied) 
01-20 11:24:25.731: W/System.err(28301): at libcore.io.IoBridge.open(IoBridge.java:460) 
01-20 11:24:25.731: W/System.err(28301): at java.io.FileOutputStream.<init>(FileOutputStream.java:88) 
01-20 11:24:25.731: W/System.err(28301): at java.io.FileOutputStream.<init>(FileOutputStream.java:128) 
01-20 11:24:25.732: W/System.err(28301): at java.io.FileOutputStream.<init>(FileOutputStream.java:117) 
01-20 11:24:25.732: W/System.err(28301): at android.media.MediaRecorder.prepare(MediaRecorder.java:693) 
01-20 11:24:25.732: W/System.err(28301): at com.cuonglm.ghiam.MainActivity.start(MainActivity.java:43) 
01-20 11:24:25.732: W/System.err(28301): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:24:25.732: W/System.err(28301): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 11:24:25.732: W/System.err(28301): at android.view.View$1.onClick(View.java:3612) 
01-20 11:24:25.732: W/System.err(28301): at android.view.View.performClick(View.java:4222) 
01-20 11:24:25.732: W/System.err(28301): at android.view.View$PerformClick.run(View.java:17620) 
01-20 11:24:25.732: W/System.err(28301): at android.os.Handler.handleCallback(Handler.java:800) 
01-20 11:24:25.733: W/System.err(28301): at android.os.Handler.dispatchMessage(Handler.java:100) 
01-20 11:24:25.733: W/System.err(28301): at android.os.Looper.loop(Looper.java:194) 
01-20 11:24:25.733: W/System.err(28301): at android.app.ActivityThread.main(ActivityThread.java:5409) 
01-20 11:24:25.733: W/System.err(28301): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:24:25.733: W/System.err(28301): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 11:24:25.733: W/System.err(28301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
01-20 11:24:25.733: W/System.err(28301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606) 
01-20 11:24:25.734: W/System.err(28301): at dalvik.system.NativeStart.main(Native Method) 
01-20 11:24:25.734: W/System.err(28301): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied) 
01-20 11:24:25.735: W/System.err(28301): at libcore.io.Posix.open(Native Method) 
01-20 11:24:25.735: W/System.err(28301): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 
01-20 11:24:25.735: W/System.err(28301): at libcore.io.IoBridge.open(IoBridge.java:444) 
01-20 11:24:25.736: W/System.err(28301): ... 19 more 
01-20 11:24:25.800: D/ServiceManager(28301): The name of the service is notification 
01-20 11:24:25.806: D/ServiceManager(28301): The name of the service is power 
01-20 11:24:25.850: D/GraphicBuffer(28301): create handle(0x5dc08f80) (w:240, h:77, f:1) 
01-20 11:24:29.307: D/GraphicBuffer(28301): close handle(0x5dc08f80) (w:240 h:77 f:1) 
01-20 11:24:32.375: I/View(28301): Touch down dispatch to android.widget.Button{41392050 VFED..C. ........ 321,448-396,520 #7f080003 app:id/button2}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=42.243225, y[0]=39.2959, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=42653543, downTime=42653543, deviceId=5, source=0x1002 } 
01-20 11:24:32.384: I/SurfaceTextureClient(28301): [STC::queueBuffer] (this:0x5ca90e00) fps:0.40, dur:7530.46, max:6579.88, min:189.37 
01-20 11:24:32.384: I/SurfaceTextureClient(28301): [STC::queueBuffer] this:0x5ca90e00, api:1, last queue time elapsed:6579.88 
01-20 11:24:32.519: I/View(28301): Touch up dispatch to android.widget.Button{41392050 VFED..C. ...P.... 321,448-396,520 #7f080003 app:id/button2}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=42.243225, y[0]=39.2959, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=42653688, downTime=42653543, deviceId=5, source=0x1002 } 
01-20 11:24:32.520: V/Provider/Settings(28301): from settings cache , name = sound_effects_enabled , value = 0 
01-20 11:24:32.525: E/MediaRecorder(28301): stop called in an invalid state: 4 
01-20 11:24:32.527: D/AndroidRuntime(28301): Shutting down VM 
01-20 11:24:32.527: W/dalvikvm(28301): threadid=1: thread exiting with uncaught exception (group=0x40e559a8) 
01-20 11:24:32.527: W/dalvikvm(28301): threadid=1: uncaught exception occurred 
01-20 11:24:32.527: W/System.err(28301): java.lang.IllegalStateException: Could not execute method of the activity 
01-20 11:24:32.528: W/System.err(28301): at android.view.View$1.onClick(View.java:3617) 
01-20 11:24:32.528: W/System.err(28301): at android.view.View.performClick(View.java:4222) 
01-20 11:24:32.529: W/System.err(28301): at android.view.View$PerformClick.run(View.java:17620) 
01-20 11:24:32.529: W/System.err(28301): at android.os.Handler.handleCallback(Handler.java:800) 
01-20 11:24:32.529: W/System.err(28301): at android.os.Handler.dispatchMessage(Handler.java:100) 
01-20 11:24:32.530: W/System.err(28301): at android.os.Looper.loop(Looper.java:194) 
01-20 11:24:32.530: W/System.err(28301): at android.app.ActivityThread.main(ActivityThread.java:5409) 
01-20 11:24:32.530: W/System.err(28301): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:24:32.531: W/System.err(28301): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 11:24:32.531: W/System.err(28301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
01-20 11:24:32.531: W/System.err(28301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606) 
01-20 11:24:32.532: W/System.err(28301): at dalvik.system.NativeStart.main(Native Method) 
01-20 11:24:32.532: W/System.err(28301): Caused by: java.lang.reflect.InvocationTargetException 
01-20 11:24:32.533: W/System.err(28301): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:24:32.533: W/System.err(28301): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 11:24:32.534: W/System.err(28301): at android.view.View$1.onClick(View.java:3612) 
01-20 11:24:32.534: W/System.err(28301): ... 11 more 
01-20 11:24:32.534: W/System.err(28301): Caused by: java.lang.IllegalStateException 
01-20 11:24:32.535: W/System.err(28301): at android.media.MediaRecorder.stop(Native Method) 
01-20 11:24:32.536: W/System.err(28301): at com.cuonglm.ghiam.MainActivity.stop(MainActivity.java:60) 
01-20 11:24:32.536: W/System.err(28301): ... 14 more 
01-20 11:24:32.537: W/dalvikvm(28301): threadid=1: calling UncaughtExceptionHandler 
01-20 11:24:32.541: E/AndroidRuntime(28301): FATAL EXCEPTION: main 
01-20 11:24:32.541: E/AndroidRuntime(28301): java.lang.IllegalStateException: Could not execute method of the activity 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.view.View$1.onClick(View.java:3617) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.view.View.performClick(View.java:4222) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.view.View$PerformClick.run(View.java:17620) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.os.Handler.handleCallback(Handler.java:800) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.os.Handler.dispatchMessage(Handler.java:100) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.os.Looper.loop(Looper.java:194) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.app.ActivityThread.main(ActivityThread.java:5409) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at dalvik.system.NativeStart.main(Native Method) 
01-20 11:24:32.541: E/AndroidRuntime(28301): Caused by: java.lang.reflect.InvocationTargetException 
01-20 11:24:32.541: E/AndroidRuntime(28301): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at java.lang.reflect.Method.invoke(Method.java:525) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.view.View$1.onClick(View.java:3612) 
01-20 11:24:32.541: E/AndroidRuntime(28301): ... 11 more 
01-20 11:24:32.541: E/AndroidRuntime(28301): Caused by: java.lang.IllegalStateException 
01-20 11:24:32.541: E/AndroidRuntime(28301): at android.media.MediaRecorder.stop(Native Method) 
01-20 11:24:32.541: E/AndroidRuntime(28301): at com.cuonglm.ghiam.MainActivity.stop(MainActivity.java:60) 
01-20 11:24:32.541: E/AndroidRuntime(28301): ... 14 more 
+0

请先添加logcat –

+0

首先添加一个条件,然后停止myaudiorecoring不为空的记录。 – Kishan

+0

您是否检查过MediaRecorder处于有效状态? [来自参考资料](http://developer.android.com/reference/android/media/MediaRecorder.html#stop()):'请注意,如果没有有效的音频/视频数据有意地将RuntimeException抛出到应用程序当stop()被调用时被接收到。并且'stop()...抛出IllegalStateException \t如果在start()之前调用它' –

回答

2
java.io.FileNotFoundException: /storage/sdcard0/myrecording.3gp: open failed: EACCES (Permission denied) 

你插入WRITE_EXTERNAL_STORAGERECORD_AUDIO许可到应用程序的清单文件?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 

阅读关于Audio Capture的官方教程。

+0

OP使用'AudioRecorder'录制声音。他/她没有尝试读取文件,他们正在尝试写入文件。尝试打开文件进行写入时会抛出'FileNotFoundException' - 它们需要具有'WRITE_EXTERNAL_STORAGE'权限。 – Squonk

+0

@Squonk但提供的logcat不包含有关写入的任何异常。 – Bishan

+0

当试图打开文件进行读取时,不仅仅会引发'FileNotFoundException' - 如果操作失败,尝试打开新文件进行写入操作时也会引发FileNotFoundException。混淆吧?严重的是,搜索stackoverflow,你会发现有关它的问题。 – Squonk

0

检查了这一点首先:

if(myAudioRecorder != null){ 
    myAudioRecorder.stop(); 
    myAudioRecorder.release(); 
    myAudioRecorder = null; 
} 

和你插入许可,原因是其是说,文件清单文件中没有发现?

0

确保您的刻录机被停止只有当录制过程中其他你能处理这样也:

 if (audio_recorder != null) { 

      // Clear recorder configuration 
      audio_recorder.reset(); 

      // Release the recorder object 
      audio_recorder.release(); 
      audio_recorder = null; 

     } 

,并且确保你已经在你的清单文件中添加了所有所需的权限。

<uses-permission android:name="android.permission.CAMERA"></uses-permission> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 
相关问题