Android Uncaught Handler: thread main exiting due to uncaught exception
<p>I am having trouble using the AudioRecord class. I have created several basic apps, but can't figure out what I am doing wrong with recording audio. First of all, I get an "uncaught handler" so nothing will even launch. Then, I am not sure what is needed to record the sound, stop it and play it. What does that .start, .stop all do and how do I use it.</p>

<pre><code>package com.dustin.audioRecord;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
//import android.media.MediaRecorder.AudioSource;
//import android.media.MediaRecorder.AudioEncoder;

public class AudioRecordActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button record_button = (Button)findViewById(R.id.record_button);
    final Button stop_button = (Button)findViewById(R.id.stop_button);
    //final Button play_button = (Button)findViewById(R.id.play_button);
    //int audioSource = 0;
    int sampleRateInHz = 44100; 
    int channelConfig = AudioFormat.CHANNEL_IN_MONO; 
    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    final int bufferSizeInBytes = AudioRecord.getMinBufferSize( sampleRateInHz, 
                                                            channelConfig, 
                                                            audioFormat);


    //final MediaRecorder recorder = new MediaRecorder();
    final AudioRecord record = new AudioRecord( MediaRecorder.AudioSource.MIC, 
                                                sampleRateInHz, 
                                                audioFormat, 
                                                channelConfig,
                                                bufferSizeInBytes);

    //final byte[] tempBuffer = new byte[bufferSizeInBytes];

    record_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            record.getAudioFormat();
            record.startRecording();

            //int buffer = record.read(tempBuffer, 0, bufferSizeInBytes);

        }
    });

    stop_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            record.stop();
            record.release();
        }
    });


}
//public static final int RECORDSTATE_RECORDING = 3;
//public static final int RECORDSTATE_STOPPED = 1;
//public static final int RECORDSTATE_INITIALIZED = 1;
//public static final int MIC = 1;
//public static final int RECORDSTATE_UNINITIALIZED = 0;
</code></pre>

<p>}</p>

<p>Here is the logcat read out:</p>

<pre><code>11-15 11:36:25.498: W/dalvikvm(349): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
11-15 11:36:25.498: E/AndroidRuntime(349): Uncaught handler: thread main exiting due to uncaught exception
11-15 11:36:25.558: E/AndroidRuntime(349): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dustin.audioRecord/com.dustin.audioRecord.AudioRecordActivity}: java.lang.IllegalArgumentException: Unsupported sample encoding. Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT.
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.os.Looper.loop(Looper.java:123)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.ActivityThread.main(ActivityThread.java:4363)
11-15 11:36:25.558: E/AndroidRuntime(349):  at java.lang.reflect.Method.invokeNative(Native Method)
11-15 11:36:25.558: E/AndroidRuntime(349):  at java.lang.reflect.Method.invoke(Method.java:521)
11-15 11:36:25.558: E/AndroidRuntime(349):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-15 11:36:25.558: E/AndroidRuntime(349):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-15 11:36:25.558: E/AndroidRuntime(349):  at dalvik.system.NativeStart.main(Native Method)
11-15 11:36:25.558: E/AndroidRuntime(349): Caused by: java.lang.IllegalArgumentException: Unsupported sample encoding. Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT.
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.media.AudioRecord.audioParamCheck(AudioRecord.java:305)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.media.AudioRecord.&lt;init&gt;(AudioRecord.java:223)
11-15 11:36:25.558: E/AndroidRuntime(349):  at com.dustin.audioRecord.AudioRecordActivity.onCreate(AudioRecordActivity.java:33)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-15 11:36:25.558: E/AndroidRuntime(349):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-15 11:36:25.558: E/AndroidRuntime(349):  ... 11 more
11-15 11:36:25.578: I/dalvikvm(349): threadid=7: reacting to signal 3
11-15 11:36:25.598: I/dalvikvm(349): Wrote stack trace to '/data/anr/traces.txt'
</code></pre>
