tags:

views:

121

answers:

0

hi, I am using the following code to use camera by using intent. In the parameter of intent i am passing ndroid.provider.MediaStore.ACTION_IMAGE_CAPTURE. It is able to open camera. But the problem is that it stops unxepectedly... The problem is that it gives null pointer exception on OnActivityResults... I have used the below code...

public class demo extends Activity {

Button ButtonClick;
int CAMERA_PIC_REQUEST = 2; 
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ButtonClick =(Button) findViewById(R.id.Camera);
    ButtonClick.setOnClickListener(new OnClickListener (){
        @Override
        public void onClick(View view)
        {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // request code

            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    if( requestCode == CAMERA_PIC_REQUEST)
    {
    //  data.getExtras()
        Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
        ImageView image =(ImageView) findViewById(R.id.PhotoCaptured);
        image.setImageBitmap(thumbnail);
    }
    else 
    {
        Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG);
    }
    super.onActivityResult(requestCode, resultCode, data);
}

}

Can any one help me to solve problem-- Rakesh