调用android的系统照相机并将刚拍的照片在ImageView里显示出来

调用android的系统相机并将刚拍的照片在ImageView里显示出来我写的代码会报错,java.lang.RuntimeException

调用android的系统相机并将刚拍的照片在ImageView里显示出来
我写的代码会报错,
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent{act=inline-data(has extras)}} to activity {包名/类名}: java.lang.NullPointerException



源代码如下,各位帮忙看一下

package com.example.xiangji;

import java.io.BufferedOutputStream;  
import java.io.File;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import java.util.Calendar;  
import java.util.Locale;  
  
import android.app.Activity;  
import android.content.Intent;  
import android.graphics.Bitmap;  
import android.os.Bundle;  
import android.os.Environment;  
import android.provider.MediaStore;  
import android.text.format.DateFormat;  
import android.util.Log;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
import android.widget.ImageView;  
import android.widget.Toast;  
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;

public class MainActivity extends Activity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
  
        button = (Button) findViewById(R.id.button);  
        button.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub   
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  
                startActivityForResult(intent, 1);  
            }  


        });  
    }  
  
@Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        // TODO Auto-generated method stub   
        super.onActivityResult(requestCode, resultCode, data);  
        if (resultCode == Activity.RESULT_OK) {  
            String sdStatus = Environment.getExternalStorageState();  
            if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用   
                Log.i("TestFile",  
                        "SD card is not avaiable/writeable right now.");  
                return;  
            }  
            String name = new DateFormat().format("yyyyMMdd_hhmmss",Calendar.getInstance(Locale.CHINA)) + ".jpg";     
            Toast.makeText(this, name, Toast.LENGTH_LONG).show();  
            Bundle bundle = data.getExtras();  
            Bitmap bitmap = (Bitmap) bundle.get("data");// 获取相机返回的数据,并转换为Bitmap图片格式   
          
            FileOutputStream b = null;  
   
            File file = new File("/sdcard/myImage/");  
            file.mkdirs();// 创建文件夹   
            String fileName = "/sdcard/myImage/"+name;  
  
            try {  


                b = new FileOutputStream(fileName);  
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件   
            } catch (FileNotFoundException e) {  
                e.printStackTrace();  
            } finally {  
                try {  
                    b.flush();  
                    b.close();  
                } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  
            ((ImageView) findViewById(R.id.imageview)).setImageBitmap(bitmap);// 将图片显示在ImageView里   
        }  
    }  

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

}
Android imageview Bitmap 系统相机
------解决方案--------------------


http://blog.csdn.net/shen332401890/article/details/9313379 参考一下