1

4.1.2 で Galaxy Nexus のカメラ LED をオンにしようとするこのクラスを開始しようとすると、ヌル ポインター例外が発生します。

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