setContentView trouble
<p>I'm trying to do this application: <a href="http://developer.android.com/guide/topics/media/audio-capture.html" rel="nofollow">http://developer.android.com/guide/topics/media/audio-capture.html</a> </p>

<p>My problem is that when I comment the line setContentView(ll); everything is ok, but the app doesn't do anything. When I discomment that line, it appears the two buttoms but when I push one of them, the app crashes. </p>

<p>I'm using an Android 2.1 AVD, API 7 and I've added the sdcard, audioOutput and audioInput.</p>

<p>I've added the lines: 
     
in the manifest file.</p>

<p>Another observation that I've made is: I don't know exactly where the audio file is storaged but I'm not sure if there is any problem with this.</p>

<p>Thank you in advance!</p>

<p>My code is:</p>

<pre><code>package com.example.helloandroid;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Button;
import android.widget.LinearLayout;
import android.view.View;
import android.view.ViewGroup;
import android.content.Context;
import android.util.Log;
/**
 * @author Natalia
 *
 */
public class HelloAndroidActivity extends Activity {
private static final String LOG_TAG = "AudioRecordTest";
private static String mFileName = null;
private RecordButton mRecordButton = null;
private MediaRecorder mRecorder = null; 
private PlayButton   mPlayButton = null; 
private MediaPlayer   mPlayer = null;

public static final int MODE_WORLD_WRITEABLE=0x00000002;


//path = "/sdcard/hola.3gp";
private void onRecord(boolean start) {
        if (start) {        
    startRecording();       
 } else { 
           stopRecording(); 
       }    
        } 
   private void onPlay(boolean start) {   
     if (start) {   
         startPlaying();  
      } else {   
         stopPlaying();     
   }    }    
private void startPlaying() { 
       mPlayer = new MediaPlayer(); 
       try {          
  mPlayer.setDataSource(mFileName); 
           mPlayer.prepare(); 
           mPlayer.start();
        } catch (IOException e) 
        { 
           Log.e(LOG_TAG, "prepare() failed");   
     }    
}   
 private void stopPlaying() {   
     mPlayer.release();      
  mPlayer = null;    }    
private void startRecording() {   
     mRecorder = new MediaRecorder();   
     mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 

        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
       mRecorder.setOutputFile(mFileName);
        try {            
mRecorder.prepare(); 
       } 
catch (IOException e) { 
           Log.e(LOG_TAG, "prepare() failed");   
     }      
 mRecorder.start();    
 } 
   private void stopRecording() { 
mRecorder.stop();        
mRecorder.release();        
mRecorder = null;   
 }
    class RecordButton extends Button { 
        boolean mStartRecording = true;
         OnClickListener clicker = new OnClickListener() { 
            public void onClick(View v) { 
                onRecord(mStartRecording); 
                if (mStartRecording) { 
                    setText("Stop recording");
                 } 
 else {            
         setText("Start recording");
                 }          
       mStartRecording = !mStartRecording;       
      }        };    
    public RecordButton(Context ctx) {  
           super(ctx);          
   setText("Start recording");  
           setOnClickListener(clicker);        }
       } 
       class PlayButton extends Button {    
     boolean mStartPlaying = true;        
 OnClickListener clicker = new OnClickListener() {          
       public void onClick(View v) {               
  onPlay(mStartPlaying);                
 if (mStartPlaying) {                  
   setText("Stop playing");                
 } else {                    
 setText("Start playing");   
              }            
     mStartPlaying = !mStartPlaying;  
           }        };     
    public PlayButton(Context ctx) {      
       super(ctx);            
 setText("Start playing");         
    setOnClickListener(clicker);        }
 }

       public void HelloAndroidActivity() {  
        mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();    
      mFileName += "/sdcard/hola.3gp";    }
       @Override            
   public void onCreate(Bundle icicle) {        
  super.onCreate(icicle);    
   LinearLayout ll = new LinearLayout(this);  
        mRecordButton = new RecordButton(this);       
   ll.addView(mRecordButton,     
         new LinearLayout.LayoutParams(             
     ViewGroup.LayoutParams.WRAP_CONTENT,          
        ViewGroup.LayoutParams.WRAP_CONTENT,          
        0));       
   mPlayButton = new PlayButton(this);     
     ll.addView(mPlayButton,      
        new LinearLayout.LayoutParams(  
                ViewGroup.LayoutParams.WRAP_CONTENT,  
                ViewGroup.LayoutParams.WRAP_CONTENT,         
         0));        
     //setContentView(ll);    
   } 
       @Override
     public void onPause() { 
         super.onPause();        
  if (mRecorder != null) {         
     mRecorder.release();  
            mRecorder = null;        }  
        if (mPlayer != null) {   
           mPlayer.release();
              mPlayer = null;       
   }    }



   }
</code></pre>

<p>I'm sorry because it is a little disaster!</p>

<p>These are my errors (I've just created a new Activity with the same code):</p>

<blockquote>
  <p>12-27 12:04:55.456: E/AndroidRuntime(411): FATAL EXCEPTION: main</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411): java.lang.IllegalStateException</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.media.MediaRecorder.start(Native Method)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at Radar.packageRadar.app.Radar2Activity.startRecording(Radar2Activity.java:60)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at Radar.packageRadar.app.Radar2Activity.onRecord(Radar2Activity.java:30)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at Radar.packageRadar.app.Radar2Activity.access$0(Radar2Activity.java:28)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at Radar.packageRadar.app.Radar2Activity$RecordButton$1.onClick(Radar2Activity.java:71)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.view.View.performClick(View.java:2408)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.view.View$PerformClick.run(View.java:8816)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.os.Handler.handleCallback(Handler.java:587)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.os.Handler.dispatchMessage(Handler.java:92)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.os.Looper.loop(Looper.java:123)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at android.app.ActivityThread.main(ActivityThread.java:4627)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at java.lang.reflect.Method.invokeNative(Native Method)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at java.lang.reflect.Method.invoke(Method.java:521)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)</p>
  
  <p>12-27 12:04:55.456: E/AndroidRuntime(411):    at dalvik.system.NativeStart.main(Native Method)</p>
</blockquote>
