[Solved] Android MediaRecorder.stop() Error: java.lang.RuntimeException: stop failed.

    E/AndroidRuntime(7698): Cause by: java.lang.RuntimeException: stop failed.
if (mediarecorder != null) {  
        mediarecorder.stop();  
        mediarecorder.release();  
        mediarecorder = null;  
        if (mCamera != null) {  
            mCamera.release();  
            mCamera = null;  
        }  
    } 

Now, in mediarecord. Stop(); This sentence is wrong, now in mediarecord. Stop(); If you add a few sentences before this sentence, you won’t make a mistake

mediarecorder.setOnErrorListener(null);
mediarecorder.setOnInfoListener(null);
mediarecorder.setPreviewDisplay(null);

After modification:

if (mediarecorder != null) {  
            //added by ouyang start  
            try {  
                //The following three parameters must be added, if not, it will crash, in mediarecorder.stop();  
                // error is reported as: RuntimeException:stop failed  
                mediarecorder.setOnErrorListener(null);  
                mediarecorder.setOnInfoListener(null);    
                mediarecorder.setPreviewDisplay(null);  
                mediarecorder.stop();  
            } catch (IllegalStateException e) {  
                // TODO: handle exception  
                Log.i("Exception", Log.getStackTraceString(e));  
            }catch (RuntimeException e) {  
                // TODO: handle exception  
                Log.i("Exception", Log.getStackTraceString(e));  
            }catch (Exception e) {  
                // TODO: handle exception  
                Log.i("Exception", Log.getStackTraceString(e));  
            }  
            //added by ouyang end  
              
            mediarecorder.release();  
            mediarecorder = null;  
            if (mCamera != null) {  
                mCamera.release();  
                mCamera = null;  
            }  
        }  

Read More: