Question

i was trying to to build an flashlight app but when i tried to run it the app stopped and gave me this error:

 03-20 12:18:39.590      437-455/system_process I/PackageManager﹕ Removing non-system package:com.example.flashlight
03-20 12:18:39.840      437-455/system_process I/PackageManager﹕ Running dexopt on: com.example.flashlight
03-20 12:18:46.340  24099-24099/com.example.flashlight E/Trace﹕ error opening trace file: No such file or directory (2)
03-20 12:18:46.360  24099-24099/com.example.flashlight W/dalvikvm﹕ Refusing to reopen boot DEX '/system/framework/hwframework.jar'
03-20 12:18:46.760  24099-24099/com.example.flashlight W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d7e438)

This is my code:

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Camera cam = android.hardware.Camera.open();
        Camera.Parameters parameters = cam.getParameters();
       ToggleButton toggleButton = (ToggleButton)findViewById(R.id.toggleButton);
        try {
            if (toggleButton.isChecked()){
                parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            } else {
                parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
            }
        } catch (Exception e){
            e.printStackTrace();
        }

my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New ToggleButton"
            android:id="@+id/toggleButton" android:layout_centerVertical="true" android:layout_centerHorizontal="true"/>
</RelativeLayout>

and my manifest.xml:

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

    <uses-sdk android:targetSdkVersion="16"
            android:minSdkVersion="9"/>

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

    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MyActivity"
                  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>
</manifest>

i understand that a deep link error has something to do with the internet but i do not have anything like that in the app. Please help cause i can't figure out what is wrong with this code.

Was it helpful?

Solution

you dont add permission to use camera. add permission and then try again.

add these

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

for reference , see here : http://developer.android.com/reference/android/hardware/Camera.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top