Error in MediaRecorder.stop() method while recording an audio file
<h2>AddRecordingActivity.java</h2>

<p><a href="http://i.stack.imgur.com/nQMCW.png" rel="nofollow">when i clicked on stop recording button then an application is unfortunately stoped</a></p>

<hr>

<pre><code>public class AddRecordingActivity extends Activity {
    Button btnHome, btnRemoveRecording;
    ImageView ivVideoRecord, ivAudioRecord, ivStopRecording;
    Chronometer stopWatch;
    Context con;
    private String outputFile = null;
    MediaRecorder audioRecorder;
    TextView tvAudioFileName;
    EditText etAudioFileName;
    Button btnYes,btnNo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        declareData();
        clickedOnAudioRecordButton();
        clickedOnVideoRecordButton();
        clickedOnStopRecordingButton();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_add_recording, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        SimpleFactory factory = new SimpleFactory();
        return factory.onCreateView(name, context, attrs);
    }

    public void declareData(){
        FontManager.getInstance().initialize(this, R.xml.fonts);
        setContentView(R.layout.activity_add_recording);
        con = AddRecordingActivity.this;
        btnHome = (Button) findViewById(R.id.bHome);
        btnRemoveRecording = (Button) findViewById(R.id.bRemoveRecording);
        ivAudioRecord = (ImageView) findViewById(R.id.ivAudioRecording);
        ivVideoRecord = (ImageView) findViewById(R.id.ivVideoRecording);
        ivStopRecording = (ImageView) findViewById(R.id.ivStopRecording);
        stopWatch = (Chronometer) findViewById(R.id.stopWatch);

        Date now = new Date();
        android.text.format.DateFormat.format("yyyy-MM-dd-hh-mm-ss", now);
       outputFile = Environment.getExternalStorageDirectory().toString()+"/recording-"+now+".3gp";
//        outputFile = Environment.getExternalStorageDirectory().getAbsolutePath()+"/recording.3gp";

        audioRecorder = new MediaRecorder();
        audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        audioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);

        ivStopRecording.setEnabled(false);
        ivStopRecording.setAlpha(0.4f);
        btnHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickedOnHomeButton();
            }
        });
    }

    public void clickedOnAudioRecordButton(){
        ivAudioRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivStopRecording.setEnabled(true);
                ivStopRecording.setAlpha(1.0f);
                stopWatch.start();

                try {
                    audioRecorder.prepare();
                    audioRecorder.start();
                    Log.d("TAG","Audio started Successfully.");
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Toast.makeText(con, "Recording started", Toast.LENGTH_LONG).show();
            }
        });
    }

    public void clickedOnVideoRecordButton(){
        ivVideoRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivStopRecording.setEnabled(true);
                ivStopRecording.setAlpha(1.0f);
                stopWatch.start();
            }
        });
    }

    public void clickedOnStopRecordingButton(){
        ivStopRecording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Date now = new Date();
                android.text.format.DateFormat.format("yyyy-MM-dd-hh-mm-ss", now);
                outputFile = Environment.getExternalStorageDirectory().toString()+"/recording-"+now+".3gp";
                final Dialog renameDialog = new Dialog(con);
                renameDialog.setContentView(R.layout.row_rename_dialog);
                renameDialog.setTitle("Rename");
                tvAudioFileName = (TextView) renameDialog.findViewById(R.id.tvRecordingName);
                etAudioFileName = (EditText) renameDialog.findViewById(R.id.etAudioRecordingName);
                btnYes = (Button) renameDialog.findViewById(R.id.btnYes);
                btnNo = (Button) renameDialog.findViewById(R.id.btnNo);
                tvAudioFileName.setText(outputFile + "?");
                etAudioFileName.setText(outputFile);

                btnYes.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        audioRecorder.setOutputFile(etAudioFileName.getText().toString().trim());
                        renameDialog.dismiss();
                    }
                });

                btnNo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        audioRecorder.setOutputFile(outputFile);
                        renameDialog.dismiss();
                    }
                });
                renameDialog.show();

                stopWatch.stop();
                audioRecorder.stop(); // here is error
                audioRecorder.release();
                audioRecorder = null;
                Toast.makeText(con, "Audio recorded successfully",Toast.LENGTH_LONG).show();
            }
        });
    }

    public void clickedOnHomeButton(){
        startActivity(new Intent(con,MainActivity.class));
        finish();
    }
}
</code></pre>

<p><a href="http://i.stack.imgur.com/DPUe2.png" rel="nofollow">when stop button is clicked, one custom dialog will be open for renaming the audio file in application</a></p>

<hr>

<h2>Logcat</h2>

<pre><code>03-05 10:35:29.145    3478-3478/com.becbingham.mybabyhelper E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.becbingham.mybabyhelper, PID: 3478
    java.lang.IllegalStateException
            at android.media.MediaRecorder.stop(Native Method)
            at com.becbingham.mybabyhelper.AddRecordingActivity$4.onClick(AddRecordingActivity.java:174)
            at android.view.View.performClick(View.java:4848)
            at android.view.View$PerformClick.run(View.java:20260)
            at android.os.Handler.handleCallback(Handler.java:815)
            at android.os.Handler.dispatchMessage(Handler.java:104)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5624)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
</code></pre>