You did not initialize your MediaRecorder:
MediaRecorder recorder;
you should do it in the onCreate method:
recorder = new MediaRecorder();
before you make use of your recorder
or you get a NullPointerException.
BTW: improve your code indentation (in Eclipse Ctrl + I keybord shortcut) to increase readability of your code
about the next problem: IllegalStateException
:
check the MediaRecorder state diagram from the android documentation:
and the provided example code:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(PATH_NAME);
recorder.prepare();
recorder.start(); // Recording is now started
...
recorder.stop();
recorder.reset(); // You can reuse the object by going back to setAudioSource() step
recorder.release(); // Now the object cannot be reused