为什么我触摸停止按钮,我的应用程序不幸关闭

时间:2014-01-20 04:12:36

标签: android

这是我的代码,我触摸停止按钮后应用程序自动关闭。我调试并跟踪“myAudioRecorder.stop()”,它有异常“error(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 tba=android.view.inputmethod.EditorInfo@413a5410 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: context=android.app.ContextImpl@41351618holder=android.app.IActivityManager$ContentProviderHolder@413a9d28noisy=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

3 个答案:

答案 0 :(得分: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的官方教程。

答案 1 :(得分:0)

首先检查一下:

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

并且您是否已插入清单文件的权限,因为它说该文件未找到?

答案 2 :(得分: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>