tag:null
shortMsg:java.lang.NullPointerException
longMsg:java.lang.NullPointerException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=Intent { }} to activity {com.test.xyoffice/com.test.xyoffice.UpPhoto}: java.lang.NullPointerException
stackTrace:java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=Intent { }} to activity {com.test.xyoffice/com.test.xyoffice.UpPhoto}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2591)
at android.app.ActivityThread.access$2000(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.test.xyoffice.UpPhoto.onActivityResult(UpPhoto.java:250)
at android.app.Activity.dispatchActivityResult(Activity.java:3932)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2545)
... 11 moreV/com.miui.camera.CameraHolder( 5816): relaseCamera
D/LibSOCJordanCamera( 1931): +stopPreview
D/LibSOCJordanCamera( 1931): -stopPreview
D/LibSOCJordanCamera( 1931): +release
E/LibSOCJordanCamera( 1931): VIDIOC_STREAMOFF issued already
D/LibSOCJordanCamera( 1931): +deinitPvOverlay
D/LibSOCJordanCamera( 1931): -deinitPvOverlay
D/TIOverlay( 2102): overlay_destroyOverlay:IN dev (0x98398) and overlay (0x42a9a0)
I/TIOverlay( 2102): Destroying overlay/fd=432/obj=0042a9a0代码public class UpPhoto extends Activity {
 public static final int NONE = 0;  
   public static final int PHOTOHRAPH = 1;// 拍照   
   public static final int PHOTOZOOM = 2; // 缩放   
   public static final int PHOTORESOULT = 3;// 结果  
   public static final String IMAGE_UNSPECIFIED = "image/*";
   public ProgressDialog pro=null;
   private String ImageName;
   private Uri uriPohto=null;
            File picPath =null;
        String path=null;
        Bitmap photo=null;
        Bitmap resizedBitmap=null;
   private TextView mText1;  
   private TextView mText2;  
   private Button mButton;
   private Button mButton1;
   private Button mButton2;
   private ImageView iv;
    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upphoto);
final TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
iv=(ImageView) findViewById(R.id.iv);

mButton=(Button) findViewById(R.id.photo);
mButton.setOnClickListener(new mButton2Listener());
mButton1=(Button) findViewById(R.id.xc);
mButton1.setOnClickListener(new mButton1Listener());
mButton2 = (Button) findViewById(R.id.mButton);  
    mButton2.setOnClickListener(new View.OnClickListener()  
    {  
     final CharSequence strDialogTitle=getString(R.string.title);
     final CharSequence strDialogBody=getString(R.string.body);
    
      private String actionUrl = "http://122.226.172.30/receive?telephone="+phoneMgr.getLine1Number();      
      //private String actionUrl = "http://122.226.172.30/telephone/"+phoneMgr.getLine1Number()+"/?p=receive_file.php"; 
      @Override  
      public void onClick(View v)  
      {  
        uploadFile(actionUrl);  
        pro=ProgressDialog.show(UpPhoto.this, strDialogTitle, strDialogBody,true);
        new Thread(){
         public void run() {
        
// TODO Auto-generated method stub
         try {
sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
 pro.dismiss();
} }
        }.start();
      }  
    });  
    
}//上传

//拍照
    class mButton2Listener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
// ImageName = "/" + getStringToday() + ".jpg";
    destorypic(); // 调用系统的拍照功能
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

// intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
// Environment.getExternalStorageDirectory(), ImageName)));
startActivityForResult(intent, PHOTOHRAPH);
}
}
    //相册
    class mButton1Listener implements OnClickListener{ @Override
public void onClick(View v) {
destorypic();
// TODO Auto-generated method stub
//打开图库选择图片
Intent intent =new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PHOTORESOULT);
}    
    }
    
    
    
    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PHOTOHRAPH) {
Toast.makeText(this, "1", Toast.LENGTH_SHORT).show();
     uriPohto = data.getData();
     Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
      if(uriPohto!=null){
      Toast.makeText(this, "3", Toast.LENGTH_SHORT).show();
       photo = BitmapFactory.decodeFile(uriPohto.getPath());
       Toast.makeText(this, "4", Toast.LENGTH_SHORT).show();
       int w=photo.getWidth();
       int h=photo.getHeight();
       Toast.makeText(this, "5", Toast.LENGTH_SHORT).show();
       int neww=320;
       int newh=240;
       Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
       float scaleWidth = ((float) neww) / w;  
       float scaleHeight = ((float) newh) / h;
       Toast.makeText(this, "3", Toast.LENGTH_SHORT).show();
     // 创建操作图片用的matrix对象   
             Matrix matrix = new Matrix();
             Toast.makeText(this, "4", Toast.LENGTH_SHORT).show();
             matrix.postScale(scaleWidth, scaleHeight);
             Toast.makeText(this, "5", Toast.LENGTH_SHORT).show();
              resizedBitmap = Bitmap.createBitmap(photo, 0, 0,   
                            w, h, matrix, true); 
              Toast.makeText(this, "6", Toast.LENGTH_SHORT).show();
       iv.setImageBitmap(resizedBitmap);
      }
      FileOutputStream fos = null;       
      BufferedOutputStream bos = null;       
      ByteArrayOutputStream baos = null;
      try {     
      baos = new ByteArrayOutputStream();     
      resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 60, baos);     
      byte[] byteArray = baos.toByteArray();   
      String saveDir  = Environment.getExternalStorageDirectory() + "/xy";
     //  Toast.makeText(this, "5", Toast.LENGTH_SHORT).show();
      File dir = new File(saveDir);       
          if (!dir.exists()) {       
              dir.mkdir();       
          }     
        ImageName = "/" + getStringToday() + ".jpg";     
       File file=new File(saveDir,ImageName);  
       file.delete();
       if(!file.exists()){  
file.createNewFile();
}     
       fos = new FileOutputStream(file);
       bos = new BufferedOutputStream(fos);
       bos.write(byteArray);   
              path=file.getPath();       }catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(baos!=null){
baos.close();
}if(bos!=null){
bos.close();
}if(fos!=null){
fos.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}     
    }
if(requestCode==PHOTORESOULT){
     Uri uri =data.getData();
     uriPohto=uri;
     System.out.println("Android客户端上的图片地址uri="+uri);
     String[] pojo ={MediaStore.Images.Media.DATA};
     Cursor cursor =managedQuery(uri, pojo, null, null, null);
     if(cursor!=null){
     ContentResolver cr =this.getContentResolver();
     int coulunm_index =cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
     cursor.moveToFirst();
     path =cursor.getString(coulunm_index);
          //   mText1 = (TextView) findViewById(R.id.mText1);
         //    mText1.setText(path);     System.out.println("真实图片路径Path:"+path);
     if(path.endsWith("jpg")||path.endsWith("png")){
     //picPath = path;
     try {
Bitmap bitmap =BitmapFactory.decodeStream(cr.openInputStream(uri));
    iv.setImageBitmap(bitmap);
     } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
     }
     }
     }


}
//获取时间
    public static String getStringToday() {
     Date currentTime = new Date();
     SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
     String dateString = formatter.format(currentTime);
     return dateString;
     }
    //销毁图像
    private void destorypic(){
     if(photo != null && !photo.isRecycled()){
     photo.recycle();
     photo=null;     }
    }
}
还有就是为何拍照功能只有在小米系统下才能实现,非小米系统拍完照点击保存照片时就报错
能否做下解答,感激不尽

解决方案 »

  1.   

    贴报错log,这个可能性太多了。
      

  2.   

    不好意思,我网络不好,刚看见代码和log。看流程上没问题,但是没有返回数据。你用个其他的三方应用,比如美图秀秀什么的,拍照试试,看看是不是相机本身有BUG。
      

  3.   


    LZ增加一个onKeyDown事件  点击back键  直接finish掉当前activity对象试试至于非小米系统拍完照点击保存照片时就报错,需LZ根据异常信息继续分析定位了   可以是点击保存时,保存的路径不存在...   没有写入的权限啊  等  都有可能~
      

  4.   


    谢谢你的回答,我增加了一个onKeyDown后还是程序停止,也不是非小米系统,应该是除了我自己手机以外的手机都不行,我测试4才手机有2.2的,有也有小米的4.0 还有4。1都不行程序停止实在点击保存图像的时候,但是照片是保存在相机默认的文件夹下 
      

  5.   

    错误很明显,需要判断是何种返回,取消的时候@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
       if (requestCode == PHOTOHRAPH) {
        //todo something
       }
    }
    else if(resultCode == RESULT_CANCEL){
    // 取消相机操作
    }