尝试在空对象引用上调用虚拟方法 'int android.graphics.Bitmap.getHeight()'

Attempt to invoke virtual method 'int android.graphics.Bitmap.getHeight()' on a null object reference

我正在从 "Gallery" 或 "Take photo" 中选择图像。我的问题是,在使用相机拍照时按下了后退键。我收到了错误。

我的密码是

if (items[position].equals("Take photo")) {
                        Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        File file= getOutputMediaFile();
                        Uri picUri = Uri.fromFile(file);
                        filepath = picUri.getPath();
                        i.putExtra(MediaStore.EXTRA_OUTPUT,picUri);
                        _a.startActivityForResult(i, 1);
                    }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    Log.e("Action", action);
    if (action.equals("add_car")) {
        if(_addLayout.filepath != null){
            filePath = _addLayout.filepath;
            _addLayout.filepath = null;
        }
        if(data != null)
        filePath = CommonUtilities.getPath(data.getData(), "Image");
        _addLayout.filepath = filePath;
        setImage(UI_AddCar.ivTakenPicture);
    }
  }

void setImage(ImageView im){
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;

     Bitmap bitmap = BitmapFactory.decodeFile(filePath);

     if(filePath != null){
         int height = bitmap.getHeight(), width = bitmap.getWidth();
            if (height > 1280 && width > 960){
                Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
                im.setImageBitmap(imgbitmap);
                im.setVisibility(View.VISIBLE);
         } else {
                im.setImageBitmap(bitmap);
                im.setVisibility(View.VISIBLE);
            }
     }

在这个UI_AddCar.ivTakenPicture中是ImageView

感谢 Piyush Gupta。我更新了条件

if(filePath != null && bitmap != null){
         int height = bitmap.getHeight(), width = bitmap.getWidth();

            if (height > 1280 && width > 960){

                    Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
                    im.setImageBitmap(imgbitmap);
                    im.setVisibility(View.VISIBLE);

            }else {

                    im.setImageBitmap(bitmap);
                    im.setVisibility(View.VISIBLE);
            }
     }