如何解决孤儿案件?

时间:2018-12-17 12:46:55

标签: java android

我使用了OnActivity Result代码,其中使用了switch语句,但是在case 2中遇到了错误

switch (requestCode) {
case (1):
    //Code for camera
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        break;

        case (2):
        //Code for Gallery
            if (resultCode == RESULT_OK) {
                Uri photoUri = data.getData();
                if (photoUri != null) {
                    try {
                    currentImage = MediaStore.Images.Media.getBitmap(
                                             this.getContentResolver(), photoUri);
                    selectedImage.setImageBitmap(currentImage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        break;
    }

    //imageView.setImageBitmap(photo);
}

1 个答案:

答案 0 :(得分:2)

如果没有case

switch (requestCode) {
    case (1):
        //Code for camera
        if (requestCode == Activity.CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
        }
        break;

    case (2):
        if (resultCode == Activity.RESULT_OK) {
            Uri photoUri = data.getData();
            if (photoUri != null) {
                try {
                    currentImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);
                    selectedImage.setImageBitmap(currentImage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        break;
}