Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Simply error; can't quite fix it.

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    Crete, Illinois
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simply error; can't quite fix it.

    Making a simple strobe light out of my camera's flash feature.
    I can't figure out why I'm getting an error on lines 31 and 32 for the
    cam.stopPreview(); 
    cam.release();
    Here's my activity;
    package com.Strobe; 
     
    import android.app.Activity; 
    import android.content.pm.PackageManager; 
    import android.hardware.Camera; 
    import android.hardware.Camera.Parameters; 
    import android.os.Bundle; 
     
    public class MainActivity extends Activity 
    { 
        /** Called when the activity is first created. */ 
        @Override 
        public void onCreate(Bundle savedInstanceState) 
        { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main); 
     
            getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); 
     
            for (int i=1;i<1000;i++) 
            { 
                for (int j=1;j<2;j++) 
                { 
                    Camera cam = Camera.open();      
                    Parameters p = cam.getParameters(); 
                    p.setFlashMode(Parameters.FLASH_MODE_TORCH); 
                    cam.setParameters(p); 
                    cam.startPreview(); 
                } 
     
                    cam.stopPreview(); 
                    cam.release(); 
            } 
        } 
    }
    Here's my layout.xml file;
    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:screenOrientation="portrait" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" > 
    <TextView   
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:text="Hello World, MainActivity" /> 
    </LinearLayout> 
    <permission android:name="android.permission.FLASHLIGHT" 
                 android:permissionGroup="android.permission-group.HARDWARE_CONTROLS" 
                 android:protectionLevel="normal" 
                 android:label="@string/permlab_flashlight" 
                 android:description="@string/permdesc_flashlight" />
    Thanks in advance!


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Simply error; can't quite fix it.

    an error
    The specifics are quite important - next time copy and paste the _entire_ error output.

    'cam' is out of scope - you declare it within the curly brackets of the for loop.

Similar Threads

  1. Simply don't understand minimax...
    By Herah in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 13th, 2011, 01:45 PM