title: Android Camera Crashes every time in onResume or onRestart
body: <p>I built a camera application from <a href="http://developer.android.com/guide/topics/media/camera.html#custom-camera" rel="nofollow noreferrer">android camera example</a>. it's working but every time my application resume or restart from onPause and onStop, my application crashes. I already tried this two <a href="https://stackoverflow.com/questions/8481402/android-i-get-no-stacktrace-phone-just-hangs">link1</a>, <a href="https://stackoverflow.com/questions/14191061/android-camera-api-app-crashes-at-onresume">link2</a> but nothing changed. How should I fix it? </p>
  
  <p>The logcat shows this message: </p>
  
  <pre><code>2169-2169/com.exshinigami.theremembrance E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.exshinigami.theremembrance, PID: 2169
  java.lang.NullPointerException
          at com.exshinigami.theremembrance.CameraPreview.surfaceCreated(CameraPreview.java:35)
          at android.view.SurfaceView.updateWindow(SurfaceView.java:572)
          at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:232)
          at android.view.View.dispatchWindowVisibilityChanged(View.java:8004)
          at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077)
          at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077)
          at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077)
          at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077)
          at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1077)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1237)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
          at android.view.Choreographer.doCallbacks(Choreographer.java:574)
          at android.view.Choreographer.doFrame(Choreographer.java:544)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5017)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>