Android Camera Preview App unexpectedly closes error
<p>Whenever i run the app, its gives an error of "Application has stopped unexpectedly" 
Pls help. Im new to android development. </p>

<p>ok here's the error log</p>

<p><a href="http://imgur.com/ZbEG4" rel="nofollow">http://imgur.com/ZbEG4</a></p>

<p>Is this giving problems : <code>mPreview = (SurfaceView)findViewById(R.id.preview);</code>
Thats my code: </p>

<pre><code>Camera mCamera = null;
private static final String TAG = "Preview";
SurfaceView mPreview = null;
SurfaceHolder mHolder = null;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);

               mPreview = (SurfaceView)findViewById(R.id.preview);
    if (mHolder == null) { 
        mHolder = mPreview.getHolder(); 
    }

    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


    mCamera = Camera.open();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mCamera.release();
    mCamera.stopPreview();

}
@Override
protected void onPause() {
    super.onPause();
}



@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    Camera.Parameters params = mCamera.getParameters();
    List&lt;Camera.Size&gt; sizes = params.getSupportedPreviewSizes();
    Camera.Size selected = sizes.get(0);
    params.setPreviewSize(selected.width, selected.height);

    mCamera.setParameters(params);
    mCamera.startPreview();     
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    try {
        if (mCamera != null) {
            mCamera = Camera.open();

            mCamera.setPreviewDisplay(mPreview.getHolder());
        }
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    if (mCamera != null) {
        mCamera.stopPreview();
    }
}
</code></pre>

<p>Xml: </p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" &gt;

    &lt;SurfaceView
        android:id="@+id/preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>
