Why does my Android App crash when loading image from gallery the 2nd time?

Posted by Sebastian on Stack Overflow See other posts from Stack Overflow or by Sebastian
Published on 2010-03-15T22:48:27Z Indexed on 2010/03/15 22:49 UTC
Read the original article Hit count: 213

Filed under:
|
|

Hi folks,

I've written an app, thats loading images either using the android gallery app or by taking a photo using the cam.

When I now load an image using the gallery, everything is fine. When the code is being executed a second time (for loading another image), the application crashes.

            try {
            Uri data = intent.getData();
            ContentResolver cr = this.getContentResolver();
            Bitmap mBitmap = null;
            mBitmap = Media.getBitmap(cr, data);
            imageView.setImageBitmap(mBitmap);
        } catch(Exception e){
            showToast(this, "Failed loading image from gallery");
            return;
        }

The code crashes at the line mBimap = Media.getBitmap(cr, data);. Everything is initialized, there are no null values etc. The strange thing is: no exception is thrown, I don't get into the catch block to determine whats going wrong.

Does anyone have an idea about this? Am I not allowed to "re-use" the content resolver? Do I have to free it after the first usage or something like this?

© Stack Overflow or respective owner

Related posts about android

Related posts about image