启动摄像头时,空指针异常

时间:2012-10-23 18:59:33

标签: java android

尝试启动此类尝试使用4.1.2打开Galaxy Nexus上的摄像头LED时出现空指针异常:     包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);
        }




}

有什么想法吗?这可能是愚蠢的,但无论如何...... 感谢

0 个答案:

没有答案