android调用系统相机拍照报错,onActivityResult中data为null

这是书上的一个练习,对着敲的,运行时拍照后点完成就出错,什么原因啊?怎么解决
图片说明

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
public static final int TAKE_PHOTO=1;
public static final int CROP_PHOTO=2;
private Button takePhoto;
private ImageView picture;
private Uri imageUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 //获取控件实例
    takePhoto=(Button) findViewById(R.id.take_photo);
    picture=(ImageView) findViewById(R.id.picture);
    takePhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //创建File对象,拥有储存拍的照片
            File outputImage=new File(Environment.getExternalStorageDirectory(),"outputImag.jpg");
            //getExternalStorageDirectory()获取手机sd卡的根目录
            try{
                if(outputImage.exists()){
                    outputImage.delete();
                }
                outputImage.createNewFile();
            }catch(IOException e){
                e.printStackTrace();
            }
                //将File对象转换成Uri对象
                imageUri=Uri.fromFile(outputImage);
                Intent intent=new Intent("android.media.action.IMAGE_CAPTURE");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); //指定保存路径
                startActivityForResult(intent,TAKE_PHOTO);//启动相机程序   拍完照后返回到onAcitvityResult()
        }
        });
        }  
     protected void onActivityResult(int requestCode, int resultCode, Intent data ){
         Log.d("MainActivity", "ok");
         switch(requestCode){
         case TAKE_PHOTO:        
         if (resultCode==RESULT_OK){
                 //执行裁剪照片的逻辑
                 Intent intent=new Intent("come.android.camera.action.CROP");
                 intent.setDataAndType(imageUri, "image/*");
                 intent.putExtra("crop", true);
                 intent.putExtra("scale", true);
                 intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);//输出文件
                 startActivityForResult(intent, CROP_PHOTO); // 启动裁剪程序  
             }
         break;
         case CROP_PHOTO:
             if(resultCode==RESULT_OK){  
                try {
                    // 用BitmapFactory的decodeStream()方法将output_image.jpg这张照片解析成Bitmap对象
                    Bitmap bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));  
                    picture.setImageBitmap(bitmap);//显示裁剪的照片
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }   
             }
               break;
             default:
               break;
         }
     }
     }

http://blog.csdn.net/huyongl1989/article/details/48751443

缺少权限设置吧
加入

//文件创建、删除权限

//文件读写权限,只针对于手机内存的SDCard,对外接SDCard无效

可能没写权限。
或者模拟器没有摄像头

模拟器一般没有摄像头的,这里是ActivityNotFound异常,应该就是这个原因,还有如果是真机小米也会出现这种情况

根据log显示是没找到action是come.android.camera.action.CROP的Activity,哈哈,应该是你的action写错了吧,应该是com.android.camera.action.CROP,你把com 写成了 come,望采纳^-^

默认情况下,不需要指定intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
照相机有自己默认的存储路径,拍摄的照片将返回一个缩略图。
如果想访问原始图片,可以通过dat extra能够得到原始图片位置。
即,如果指定了目标uri,data就没有数据,如果没有指定uri,则data就返回有数据!
你这里指定了路径,那你直接去找到那个路径加载那个图片即可。

可能是缺少权限,也能两个参数写错了

缺少权限,设置添加CROP的权限


应该是指定了uri的原因,可以参考上面的文章