title: android flashlight second launch error
body: <p>Im trying to make a very basic flashlight app. When the user opens the app no layout will be inflated, the flashlight will just turn on. Once the user opens the for the second time the flashlight will turn off. It seems as if turning on the flashlight is no hassle but when it comes to turning it off when the app launches for the second time,thats where im a little unsure. I keep getting this error:</p>
  
  <pre><code>Process: com.example.rifatrashid.lighter, PID: 16558
          java.lang.RuntimeException: Unable to resume activity        {com.example.rifatrashid.lighter/com.example.rifatrashid.lighter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera$Parameters.setFlashMode(java.lang.String)' on a null object reference
          at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2951)
          at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2982)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
          at android.app.ActivityThread.access$800(ActivityThread.java:144)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera$Parameters.setFlashMode(java.lang.String)' on a null object reference
          at com.example.rifatrashid.lighter.MainActivity.onResume(MainActivity.java:33)
          at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1241)
          at android.app.Activity.performResume(Activity.java:6019)
          at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2940)
  </code></pre>
  
  <p>            </p>
  
  <pre><code>public class MainActivity extends Activity {
  private boolean haslight;
  private Integer val = 0;
  private Camera camera;
  private Camera.Parameters parameters;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  haslight = getApplicationContext().getPackageManager().hasSystemFeature((PackageManager.FEATURE_CAMERA_FLASH));
  if(!haslight) {
  
  }
  camera = Camera.open();
  parameters = camera.getParameters();
  val++;
  if(val&gt;1)
      val=0;
  switch (val){
      case 1:
          parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
          camera.setParameters(parameters);
          camera.startPreview();
          break;
      case 0:
          camera.stopPreview();
          camera.release();
          break;
  }
  }
  }
  </code></pre>