Android网址openStream'close'未调用

时间:2015-08-12 18:16:20

标签: android

我已经在我的应用中启用了严格模式来检查任何未关闭的游标/输入流。

我遇到了一个障碍,它一直告诉我,我没有正确关闭输入流,尽管已经关闭了。

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        AddressBookContact _abContact;

        public DownloadImageTask(AddressBookContact abContact) {
            _abContact = abContact;
        }

        protected Bitmap doInBackground(String... urls) {
            Bitmap mIcon11 = null;
            InputStream in = null;
            try {
//Load photo from URL
                URL url = new java.net.URL(_abContact.getPhoto());
                in = url.openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if(in != null) IOUtils.close(in);
            }
            return mIcon11;
        }

        protected void onPostExecute(Bitmap result) {

            ....
        }

错误一直发生在这一行

in = url.openStream();

这是在我有机会关闭它之前?不知道发生了什么......

这是它给我的错误

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called

0 个答案:

没有答案