1

尝试启动此类尝试使用 4.1.2 打开 Galaxy Nexus 上的摄像头 LED 时出现空指针异常:package com.quinny898.doorcontrol;

import android.app.*;
import android.content.*;
import android.hardware.*;
import android.os.*;
import android.view.*;
import com.quinny898.gcse.doorcontrol.*;
import java.util.*;

import com.quinny898.gcse.doorcontrol.R;

public class DoorControlDoing extends Activity {
    /** Called when the activity is first created. */


//Create camera and parameter objects
    private Camera mCamera;
    private Camera.Parameters mParameters;
    private boolean mbTorchEnabled = false;

    @Override

    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.doing);
        if(mCamera != null){
            mCamera.release();
        }
//... later in a click handler or other location, assuming that the mCamera object has already been instantiated with Camera.open()
    mParameters = mCamera.getParameters();
//Get supported flash modes
    List flashModes = mParameters.getSupportedFlashModes ();
//Make sure that torch mode is supported
//EDIT - wrong and dangerous to check for torch support this way
//if(flashModes != null && flashModes.contains("torch")){
    if(flashModes != null && flashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)){
        if(mbTorchEnabled){
        //Set the flash parameter to off
    mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
        }
        else{
//Set the flash parameter to use the torch
mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);}
//Commit the camera parameters
mCamera.setParameters(mParameters);
mbTorchEnabled = !mbTorchEnabled;
}}



        public void onBackPressed(){
            return;
        }


        public void restart(View view) {
            Intent myIntent = new Intent(DoorControlDoing.this,
                       DoorControlActivity.class); 
                       DoorControlDoing.this.startActivity(myIntent);
        }

        public void exit(View view) {
         Intent intent = new
         Intent(Intent.ACTION_MAIN);
         intent.addCategory(Intent.CATEGORY_HOME);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity(intent);
        }




}

有任何想法吗?这可能是一些愚蠢的事情,但无论如何......谢谢

4

0 回答 0