5

I am trying to make my app turn on the led. Whenever I run this code, it crashes. The app closes and gives runtime exception: FATAL Exception, java.lang.nullpointerexception.

    Camera cam = Camera.open();     
    cam.getParameters().setFlashMode(Parameters.FLASH_MODE_TORCH);
    cam.setParameters(cam.getParameters());
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
DriodPixel
  • 51
  • 1

1 Answers1

0

Well, first of all your code won't work even if it didn't crash, as you would need something like:

Parameters params = cam.getParameters().setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(params);

However, that won't fix your crash; instead it seems that turning on torch mode is not a simple task, according to posts like this:

Within the answers, this one seems to cover most of the options.

Community
  • 1
  • 1
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114