title: getting null pointer exception on camera set parameters
body: <p>I'm getting an error of a NullPointerException and it is referencing the line Camera.Parameters:</p>
  
  <pre><code>    @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int w,
          int h) {
      // TODO Auto-generated method stub
          Log.e(TAG, "surfaceChanged");
  
          if (mPreviewRunning) {
               mCamera.stopPreview();
               mPreviewRunning = false;
               Log.e(TAG, "stopPeview");
              }
          Camera.Parameters p = mCamera.getParameters();
          Log.e(TAG, "paarameters");
  
          p.setPreviewSize(w, h);
  
          mCamera.setParameters(p);  
          Log.e(TAG, " set parameters");
              try {
                  mCamera.setPreviewDisplay(holder);
  
                  Log.e(TAG, "setPreview");
                  } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              mCamera.startPreview();
              mPreviewRunning = true;
      }   
  </code></pre>
  
  <p>Could anyone tell me what the error is in the above code.</p>
  
  <p>I will have to test it again to get the log, but here is the entire code.  I did alter the manifest.</p>
  
  <pre><code>public class Picture extends Activity implements SurfaceHolder.Callback{
  
  private String TAG;
  private LayoutInflater mInflater = null;
  private Camera mCamera;
  boolean mPreviewRunning = false;
  private SurfaceHolder mSurfaceHolder;
  private SurfaceView mSurfaceView;
  Button takepicture;
  byte[] tempdata;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  
      getWindow().setFormat(PixelFormat.TRANSLUCENT);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
      setContentView(R.layout.camera_surface);
  
      mCamera = getCameraInstance (); 
  
      mSurfaceView = (SurfaceView)findViewById(R.id.surface_camera);
      mSurfaceHolder = mSurfaceView.getHolder();
      mSurfaceHolder.addCallback(this);
      mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
      mInflater = LayoutInflater.from(this);
      View overView = mInflater.inflate(R.layout.cameraoverlay, null);
      this.addContentView(overView, new LayoutParams(LayoutParams.FILL_PARENT,
              LayoutParams.FILL_PARENT));
  
      takepicture = (Button) findViewById(R.id.button);
      takepicture.setOnClickListener(new OnClickListener() {
  
      public void onClick(View view) {
                  mCamera.takePicture(shutterCallback, mPictureCallback,
                  jpegCallback);
          }
      });
  
  }
  
  private Camera getCameraInstance() {
      // TODO Auto-generated method stub
      Camera mCamera = null;
      try {
          mCamera = Camera.open();
      } catch (Exception e) {
  
      }
      return mCamera;
  }
  
  
  ShutterCallback shutterCallback = new ShutterCallback() {
      @Override
      public void onShutter() {}
  };
      PictureCallback mPictureCallback = new PictureCallback() {
      public void onPictureTaken(byte[] data, Camera c) {}
  };
  PictureCallback jpegCallback = new PictureCallback() {
          public void onPictureTaken(byte[] data, Camera c) {
              if(data != null) {
                  tempdata=data;
                  done();
              }
          }
      };
  
      void done(){
          Bitmap bm = BitmapFactory.decodeByteArray(tempdata, 0, tempdata.length);
          String url = Images.Media.insertImage(getContentResolver(),
                  bm, null, null);        
          bm.recycle();
          Bundle bundle = new Bundle();
          if(url!=null) {
              bundle.putString("url", url);
  
              Intent mIntent = new Intent();
              mIntent.putExtras(bundle);
              setResult(RESULT_OK, mIntent);          
          } else {
              Toast.makeText(this, "Picture can not be saved",
                              Toast.LENGTH_SHORT).show();
          }
          finish();
      }
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int w,
          int h) {
      // TODO Auto-generated method stub
          Log.e(TAG, "surfaceChanged");
  
          if (mPreviewRunning) {
               mCamera.stopPreview();
               mPreviewRunning = false;
               Log.e(TAG, "stopPeview");
              }
          Camera.Parameters p = mCamera.getParameters();
          Log.e(TAG, "paarameters");
  
          p.setPreviewSize(w, h);
  
          mCamera.setParameters(p);  
          Log.e(TAG, " set parameters");
              try {
                  mCamera.setPreviewDisplay(holder);
  
                  Log.e(TAG, "setPreview");
                  } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              mCamera.startPreview();
              mPreviewRunning = true;
      }   
  
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
      Log.e(TAG, "surfaceCreated");
      try {
      mCamera = Camera.open();
      Log.e(TAG, "camera open");
  
      } catch(Exception e) {}
  
      }
  
  
  
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
      Log.e(TAG, "surfaceDestroyed");
  
      mCamera.stopPreview();  
      mPreviewRunning = false;
      mCamera.release();        // release the camera for other applications
      mCamera = null;
  
  }
  }
  </code></pre>
  
  <p>Also, the line the log referenced was the line: Camera.Parameters p = mCamera.getParameters();</p>