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 9175533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:55:50+00:00 2026-06-17T16:55:50+00:00

[WORIKING CODE / 22.01.2013] Following code is not working and I don’t know why.

  • 0

[WORIKING CODE / 22.01.2013]

Following code is not working and I don’t know why.
I set the permissions and the button so that it should works…

I set the permissions in the manifest like this:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="spicysoftware.spicytaschenlampe"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.CAMERA" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="spicysoftware.spicytaschenlampe.FlashLight"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

And that’s the code: (It works to set the flashlight on but not off…)

Parameters p;
Camera cam;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    check_for_flash();

    cam = Camera.open();     
    cam.startPreview();
    p = cam.getParameters();

    Button cmd_flash_light = (Button) findViewById(R.id.cmd_flash_light);

    cmd_flash_light.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {


            if(p.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_TORCH)){
                Log.v("FLASH_LIGHT_ON", "TRUE");
                //p.setFlashMode(Parameters.FLASH_MODE_OFF);
            } else {
                Log.v("FLASH_LIGHT_ON", "FALSE");
                p.setFlashMode(Parameters.FLASH_MODE_TORCH);
            }

            cam.setParameters(p);

        }
    });

}

And this is the logcat error:

01-22 08:11:00.290: D/AndroidRuntime(12239): Shutting down VM
01-22 08:11:00.290: W/dalvikvm(12239): threadid=1: thread exiting with uncaught exception (group=0x40dfc2a0)
01-22 08:11:00.290: E/AndroidRuntime(12239): FATAL EXCEPTION: main
01-22 08:11:00.290: E/AndroidRuntime(12239): java.lang.RuntimeException: Fail to connect to camera service
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.hardware.Camera.native_setup(Native Method)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.hardware.Camera.<init>(Camera.java:353)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.hardware.Camera.open(Camera.java:330)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at spicysoftware.spicytaschenlampe.FlashLight$1.onClick(FlashLight.java:28)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.view.View.performClick(View.java:4223)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.view.View$PerformClick.run(View.java:17275)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.os.Handler.handleCallback(Handler.java:615)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.os.Looper.loop(Looper.java:137)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at android.app.ActivityThread.main(ActivityThread.java:4898)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at java.lang.reflect.Method.invoke(Method.java:511)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
01-22 08:11:00.290: E/AndroidRuntime(12239):    at dalvik.system.NativeStart.main(Native Method)
  • 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-17T16:55:51+00:00Added an answer on June 17, 2026 at 4:55 pm

    Make this changes in your manifest :

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="true"/>
    

    After you do your Camera.open() and after you set the parametrs, do a mCamera.startPreview(). That should do the trick.

    Declare Camera cam before onClick()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know i can do something similar to this (not working) code
Working SQL The following code works as expected, returning two columns of data (a
The following code is working, in that it returns the document in the console:
I found this datepicker events but not working on IE. I don't know what
In the following (working) code example, the templated register_enum() function is used to iterate
Possible Duplicate: xcode code sense color/completion not working Code loses syntax color in Xcode
Does anybody know of a working code example of the sum-product algorithm for (loopy)
I have some working code that uses a SQL select statement within it. As
I have some working code that uses IImgCtx to load images, but I can't
Consider the following non-working code: typedef map<int, unsigned> mymap; mymap m; for( int i

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.