java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} to activity

前端 未结 12 1212
你的背包
你的背包 2020-11-29 01:31

My app allows the user to press a button, it opens the camera, they can take a photo and it will show up in an imageview. If the user presses back or cancel while the camera

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 02:15

    If the user cancel the request, the data will be returned as NULL. The thread will throw a nullPointerException when you call data.getExtras().get("data");. I think you just need to add a conditional to check if the data returned is null.

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == CAMERA_REQUEST) {
           if (data != null)
           {         
               Bitmap photo = (Bitmap) data.getExtras().get("data"); 
               imageView.setImageBitmap(photo);
           }
    }  
    

提交回复
热议问题