I have images in my drawables folder. Activity opens them, I choose the needed images and click on button. They must be saved on my SD Card through `ImageSavingTask` class instance execution which extends `AsyncTask`.

[![Here's what my MainActivity looks like.](https://i.stack.imgur.com/Udvwc.png)](https://i.stack.imgur.com/Udvwc.png)

Here is my `onClick` code:

```
@Override
public void onClick(View v) {
    for (int i = 0; i < 26; i++)
        if (checkBoxes[i].isChecked()) {
            imageIndex = new ImageIndex(); //ImageIndex-a class with single index field which reserves the checked checkbox indexes.
            imageIndex.index = i;
            Bitmap bitmap = ((BitmapDrawable) (images[i].getDrawable())).getBitmap();
            SaveImageTask saveImageTask = new SaveImageTask();
            saveImageTask.execute(bitmap); //The class SaveImageTask extends AsyncTask<Bitmap, Void, Void>
        }
}

```

Then the selected images are handled in `doInBackground` method.

```
    @Override
    protected Void doInBackground(Bitmap... params) {
        FileOutputStream outStream = null;
        try {
            Bitmap bitmap = params[0];
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] imageBytes = stream.toByteArray();

            File sdCard = Environment.getExternalStorageDirectory();
            Drawable drawable = new BitmapDrawable(getResources(), bitmap);
            File dir = new File(sdCard.getAbsolutePath());
            dir.mkdirs();

            String fileName = "Saved image " + imageIndex.index; //The reserved index of checkbox creates a name for the new file.
            File outFile = new File(dir, fileName);

            outStream = new FileOutputStream(outFile);
            outStream.write(imageBytes);
            outStream.flush();
            outStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

```

The `<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />` line is added in my manifest.

After I connect the USB to my phone, no error happens, but no images are saved to my SD Card. And I can't find images on my phone using windows search. Debugging doesn't give any answer. What kind of problem this could be?

[![No errors on debug](https://i.stack.imgur.com/MmMjW.png)](https://i.stack.imgur.com/MmMjW.png)