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

The Archive Base Latest Questions

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

I have this code in the main activity: package flash.light.pro; import android.os.Bundle; import android.app.Activity;

  • 0

I have this code in the main activity:

package flash.light.pro;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.graphics.Color;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.view.View.OnLongClickListener;


public class MainActivity extends Activity {
    private boolean isBlack = false;
    private boolean isLedOn = false;
    private boolean supportsCamera = true;
    private Camera camera;
    final Parameters p = camera.getParameters();
    protected void onStop() {
        super.onStop();

        if (camera != null) {
            camera.release();
        }
    }

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

        setContentView(R.layout.activity_main);
        final Button screen = (Button) findViewById (R.id.screen);
        Context context = this;
        PackageManager pm = context.getPackageManager();

        isBlack = false;
        setBrightness(255);

        if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            Log.e("err", "Device has no camera!");
            supportsCamera = false;
        }


        try{
            camera = Camera.open();
        } catch (Exception e){
            Log.e(getString(R.string.app_name), "failed to open Camera");
            e.printStackTrace();
        }

        screen.setOnClickListener(new Button.OnClickListener(){  
            public void onClick(View v) { 
                if (isBlack){ 
                    screen.setBackgroundColor(Color.WHITE);
                    isBlack = false;
                    setBrightness(255);
                }
                else{
                    screen.setBackgroundColor(Color.BLACK);
                    isBlack = true;
                    setBrightness(0);
                }
            }
        });

        if(supportsCamera){
            screen.setOnLongClickListener(new OnLongClickListener() {
                public boolean onLongClick(View v) {
                    if(isLedOn){
                        p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                        camera.setParameters(p);
                        camera.startPreview();
                        return true;
                    }
                    else{
                        p.setFlashMode(Parameters.FLASH_MODE_OFF);
                        camera.setParameters(p);
                        camera.stopPreview();
                        return true;
                    }
                }
            });
        }
    }

    private void setBrightness(int brightness) {
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.screenBrightness = brightness / 100.0f;
        getWindow().setAttributes(layoutParams);
    }
}

and this androidManifest.xml code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="flash.light.pro"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
     <permission android:name="android.permission.FLASHLIGHT"
             android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
             android:protectionLevel="normal"
             android:label="string/permlab_flashlight"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

this is the LogCat logs:

11-14 20:05:06.772: D/AndroidRuntime(380): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-14 20:05:06.772: D/AndroidRuntime(380): CheckJNI is ON
11-14 20:05:07.371: D/AndroidRuntime(380): Calling main entry com.android.commands.pm.Pm
11-14 20:05:07.392: D/AndroidRuntime(380): Shutting down VM
11-14 20:05:07.400: I/AndroidRuntime(380): NOTE: attach of thread 'Binder Thread #3' failed
11-14 20:05:07.411: D/dalvikvm(380): GC_CONCURRENT freed 101K, 71% free 297K/1024K, external 0K/0K, paused 1ms+1ms
11-14 20:05:07.411: D/dalvikvm(380): Debugger has detached; object registry had 1 entries
11-14 20:05:07.830: D/AndroidRuntime(390): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-14 20:05:07.830: D/AndroidRuntime(390): CheckJNI is ON
11-14 20:05:08.390: D/AndroidRuntime(390): Calling main entry com.android.commands.am.Am
11-14 20:05:08.420: I/ActivityManager(61): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] 

flg=0x10000000 cmp=flash.light.pro/.MainActivity } from pid 390
11-14 20:05:08.450: I/ActivityManager(61): Start proc flash.light.pro for activity flash.light.pro/.MainActivity: pid=398 uid=10040 gids={1006}
11-14 20:05:08.480: D/AndroidRuntime(390): Shutting down VM
11-14 20:05:08.490: D/dalvikvm(390): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 1ms+3ms
11-14 20:05:08.500: D/dalvikvm(390): Debugger has detached; object registry had 1 entries
11-14 20:05:09.270: D/AndroidRuntime(398): Shutting down VM
11-14 20:05:09.270: W/dalvikvm(398): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-14 20:05:09.330: E/AndroidRuntime(398): FATAL EXCEPTION: main
11-14 20:05:09.330: E/AndroidRuntime(398): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

{flash.light.pro/flash.light.pro.MainActivity}: java.lang.NullPointerException
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.os.Looper.loop(Looper.java:123)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.ActivityThread.main(ActivityThread.java:3683)
11-14 20:05:09.330: E/AndroidRuntime(398):  at java.lang.reflect.Method.invokeNative(Native Method)
11-14 20:05:09.330: E/AndroidRuntime(398):  at java.lang.reflect.Method.invoke(Method.java:507)
11-14 20:05:09.330: E/AndroidRuntime(398):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-14 20:05:09.330: E/AndroidRuntime(398):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-14 20:05:09.330: E/AndroidRuntime(398):  at dalvik.system.NativeStart.main(Native Method)
11-14 20:05:09.330: E/AndroidRuntime(398): Caused by: java.lang.NullPointerException
11-14 20:05:09.330: E/AndroidRuntime(398):  at flash.light.pro.MainActivity.<init>(MainActivity.java:22)
11-14 20:05:09.330: E/AndroidRuntime(398):  at java.lang.Class.newInstanceImpl(Native Method)
11-14 20:05:09.330: E/AndroidRuntime(398):  at java.lang.Class.newInstance(Class.java:1409)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-14 20:05:09.330: E/AndroidRuntime(398):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-14 20:05:09.330: E/AndroidRuntime(398):  ... 11 more
11-14 20:05:09.410: W/ActivityManager(61):   Force finishing activity flash.light.pro/.MainActivity
11-14 20:05:09.940: W/ActivityManager(61): Activity pause timeout for HistoryRecord{4060c450 flash.light.pro/.MainActivity}
11-14 20:05:20.739: W/ActivityManager(61): Activity destroy timeout for HistoryRecord{4060c450 flash.light.pro/.MainActivity}
11-14 20:06:00.031: I/dalvikvm(61): Jit: resizing JitTable from 1024 to 2048
11-14 20:06:19.377: D/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol
11-14 20:08:35.071: I/Process(398): Sending signal. PID: 398 SIG: 9
11-14 20:08:35.081: I/ActivityManager(61): Process flash.light.pro (pid 398) has died.
11-14 20:08:35.111: W/InputManagerService(61): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub

$Proxy@4051a740

The app crashes on start up, no errors and the log is not clear for me. What can I do to fix it. By the why the app should be some sort of FlashLight. Thanks for the help.

  • 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-14T09:52:44+00:00Added an answer on June 14, 2026 at 9:52 am
    private Camera camera;
    final Parameters p = camera.getParameters();
    

    camera is not yet initialized

    I was able to find that out by looking at your 22nd line as the logcat output indicates. Don’t be overwhelmed by the amount of information in the logcat, usually finding the first instance of your package name will indicate what/where the problem is.

    Edit: as a sidenote, your package name should be in reverse domain order. So for instance if your app is called flashlightpro and your domain name is example.com, your package name should be com.example.flashlightpro. It’s not required, but it’s a standard convention.

    Edit 2: Change the declaration of camera to: Camera camera = Camera.open();

    Edit 3: The Android documentation deals with taking a picture, but steps 1, 2, 3, 10 are important in your case:

    Obtain an instance of Camera from open(int).
    Get existing (default) settings with getParameters().
    If necessary, modify the returned Camera.Parameters object and call setParameters(Camera.Parameters).
    ...
    Important: Call release() to release the camera for use by other applications. Applications should release the camera immediately in onPause() (and re-open()it in onResume()).
    

    http://developer.android.com/reference/android/hardware/Camera.html

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

Sidebar

Related Questions

I have this code: package com.problemio; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View;
I have this code: package org.example.Threading; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message;
i have this code package com.tct.soundTouch; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.MotionEvent;
So, I have this code: package com.example.ponto_2d; import android.app.Activity; import android.view.Menu; import android.view.MotionEvent; import
package com.competitivegamingaudio; import android.app.Activity; import android.content.Context; import android.location.*; import android.os.Bundle; import android.util.Log; import android.widget.*;
This is the code from my MainActivity: package com.simple.flashlight; import android.os.Bundle; import android.app.Activity; import
package com.parseador.prueba; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class main extends
I have this code, for a android app i'm working on: package com.exercise.AndroidInternetTxt; import
Here is my main: package com.example.frags; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.support.v4.app.Fragment;
Please take a look at my code: package com.yarin.android.Examples_04_23; import android.app.Activity; import android.app.Notification; import

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.