开发者

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

开发者 https://www.devze.com 2022-12-22 20:29 出处:网络
I\'ve written an app, thats loading images either using the android gallery app or by taking a photo using the cam.

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 initial开发者_如何学运维ized, 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号