Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:25:52+00:00 2026-06-15T09:25:52+00:00

Im working on a program where you can start your flashlight in your phone.

  • 0

Im working on a program where you can start your flashlight in your phone.
I’ve searched alot and got the same answear on how to do. But when I try to do the same i get a nullpointerException

So my XML is looking like
`

<Button
    android:id="@+id/StrongFlashlight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="143dp"
    android:onClick="StrongFlashlight"
    android:text="@string/flashlightMax" />`

And my Code is looking like

    public void StrongFlashlight(View view){
    Button strongFlashlightButton = (Button)findViewById(R.id.StrongFlashlight);
    camera = Camera.open();
    Parameters params = camera.getParameters();

    params.setFlashMode(Parameters.FLASH_MODE_ON);
    camera.setParameters(params);
    camera.startPreview();
    newPhoneImage = getResources().getDrawable(R.drawable.flashlight_on);
    imageView.setImageDrawable(newPhoneImage);
    strongFlashlightButton.setText("Strong Light");

}

and I’ve declared Camera camera;
Drawable newPhoneImage;

above the onCreate.

When i press the button for the “Strong Light” I get a nullpointerException at Parameters params = camera.getParameters();

So what can I do to fix this? What have I done wrong?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:25:53+00:00Added an answer on June 15, 2026 at 9:25 am

    You’re getting this error because your call to Camera.open() returns null. This happend when the device doesn’t have a back facing camera, as stating in the documentation for Camera.open().

    Creates a new Camera object to access the first back-facing camera on the device. If the device does not have a back-facing camera, this returns null.

    However, you could fix this by using:

     camera = Camera.open(int);
    

    Where the int is a Camera ID as returned by getNumberOfCameras(). You can find the details of a camera from its ID by using getCameraInfo().

    However, in most cases you can access the front camera with the camera ID 0:

     camera = Camera.open(0);
    

    Additionally, if a device doesn’t have a back facing camera, it is unlikely to have a flash light installed.

    You can check the availability of a flash using:

    boolean hasFlashLight = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im working right now on a program that can divide, add, ect, but, im
how can i make java program working with multiple languages (frensh, english , arabic
I am working on an Android 3.0 program that can connect to a SSL'd
How can I change the current working directory from within a Java program? Everything
I'm trying to get a simple winsock program working, so I create my socket
I am working on an assignment which to create a program that can read
I am working remotely and had to restart. I can start a vnc session
With AdHoc provisioning profile I can't start my application on iPhone. I get this
I am trying to get crash dump debugging working with 2010, but it keeps
Can someone tell me why my program is working weird. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.