when the user hits picagain button it occurs an error  and how to use auto focus
<p>when you click on the picagain button there is an error and i am trying to fix it but no idea what is wrong.Plus I am trying to use auto focus i have no idea where to put.
--Camera activity class-------</p>

<pre><code>public class CameraActivity extends Activity {
 private static final String TAG = "CameraDemo";
 Preview preview; // &lt;1&gt;
 Button buttonClick; // &lt;2&gt;
Intent intImg;
String imgPath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 Bundle extras = getIntent().getExtras(); 

if (extras != null)
{
    imgPath = extras.getString("delete");
}
else
{

    imgPath=String.format("/sdcard/Pictures/%d.jpg",System.currentTimeMillis());    
}

preview = new Preview(this); // &lt;3&gt;
((FrameLayout) findViewById(R.id.preview)).addView(preview); // &lt;4&gt;

buttonClick = (Button) findViewById(R.id.buttonClick);
buttonClick.setOnClickListener(new OnClickListener() {
  public void onClick(View v) { // &lt;5&gt;
    preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
  }
});

Log.d(TAG, "onCreate'd");
</code></pre>

<p>}</p>

<pre><code>// Called when shutter is opened
ShutterCallback shutterCallback = new ShutterCallback() { // &lt;6&gt;
   public void onShutter() {
   Log.d(TAG, "onShutter'd");
  }
};

// Handles data for raw picture
PictureCallback rawCallback = new PictureCallback() { // &lt;7&gt;
  public void onPictureTaken(byte[] data, Camera camera) {
    Log.d(TAG, "onPictureTaken - raw");
  }
};

// Handles data for jpeg picture
PictureCallback jpegCallback = new PictureCallback() { // &lt;8&gt;
  public void onPictureTaken(byte[] data, Camera camera) {
  FileOutputStream outStream = null;
  try {
    // Write to SD Card

    outStream = new FileOutputStream(imgPath); // &lt;9&gt;
    outStream.write(data);
    outStream.close();
    intImg = new Intent(CameraActivity.this, DisplayImg.class);
    intImg.putExtra("imgPath",imgPath);
    startActivity(intImg);
    Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
  } catch (FileNotFoundException e) { // &lt;10&gt;
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
  }
  Log.d(TAG, "onPictureTaken - jpeg");
}
</code></pre>

<p>};</p>

<p>}
------------------preview class ---------------</p>

<pre><code>class Preview extends SurfaceView implements SurfaceHolder.Callback { // &lt;1&gt;
 private static final String TAG = "Preview";

 SurfaceHolder mHolder;  // &lt;2&gt;
 public Camera camera; // &lt;3&gt;

Preview(Context context) {
  super(context);

  // Install a SurfaceHolder.Callback so we get notified when the
  // underlying surface is created and destroyed.
  mHolder = getHolder();  // &lt;4&gt;
  mHolder.addCallback(this);  // &lt;5&gt;
  mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // &lt;6&gt;
}

// Called once the holder is ready
public void surfaceCreated(SurfaceHolder holder) {  // &lt;7&gt;
  // The Surface has been created, acquire the camera and tell it where
  // to draw.
camera = Camera.open(); // &lt;8&gt;
try {
  camera.setPreviewDisplay(holder);  // &lt;9&gt;

  camera.setPreviewCallback(new PreviewCallback() { // &lt;10&gt;
    // Called for each frame previewed
    public void onPreviewFrame(byte[] data, Camera camera) {  // &lt;11&gt;
      Log.d(TAG, "onPreviewFrame called at: " + System.currentTimeMillis());
      Preview.this.invalidate();  // &lt;12&gt;
    }
  });
} catch (IOException e) { // &lt;13&gt;
  e.printStackTrace();
}
</code></pre>

<p>}</p>

<pre><code>// Called when the holder is destroyed
public void surfaceDestroyed(SurfaceHolder holder) {  // &lt;14&gt;
  camera.stopPreview();
  camera = null;
</code></pre>

<p>}</p>

<pre><code>// Called when holder has changed
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // &lt;15&gt;
  camera.startPreview();
}
</code></pre>

<p>}</p>

<p>-----DisplayImg class------</p>

<pre><code>public class DisplayImg extends Activity {
Button btn1,btn2;
 File imgFile; 
 String imgPath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.displayimg);
    btn1 = (Button) findViewById(R.id.picagain);
    btn2 = (Button) findViewById(R.id.dosurvey);
    Bundle extras = getIntent().getExtras(); 

    if (extras != null)
    {
        imgPath = extras.getString("imgPath");
        imgFile = new  File(imgPath);
         if(imgFile.exists())
         {

                Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                ImageView myImage = (ImageView) findViewById(R.id.imgView);
                myImage.setImageBitmap(myBitmap);
         }
    }
    btn1.setOnClickListener(new View.OnClickListener() {
         public void onClick(View arg0) {
         imgFile.delete();
         finish();
         Intent goback = new Intent(DisplayImg.this, CameraActivity.class);
         goback.putExtra("delete",imgPath);
         startActivity(goback);
         } 
      });
    btn2.setOnClickListener(new View.OnClickListener() {
         public void onClick(View arg0) {
         Intent dosurvey = new Intent(DisplayImg.this, SurveyBrowser.class);
         dosurvey.putExtra("imgpath",imgPath);
         startActivity(dosurvey);
         } 
      });

    // TODO Auto-generated method stub
}
</code></pre>

<p>}</p>
