android映像加载java.io.IOException:BufferedInputStream已关闭

android映像加载java.io.IOException:BufferedInputStream已关闭,android,android-contacts,android-image,Android,Android Contacts,Android Image,您好,我在我的应用程序中获取联系人图像,然后应用程序正在运行,但我在cat日志中遇到类似这样的错误。如何解决此问题..请参阅下面的代码帮助我 在java.io.BufferedInputStream.streamClosed处(BufferedInputStream.java:118) 在java.io.BufferedInputStream.read处(BufferedInputStream.java:279) 如果联系人上没有照片,则返回的InputStream为空。在尝试解码图像之前,您应

您好,我在我的应用程序中获取联系人图像,然后应用程序正在运行,但我在cat日志中遇到类似这样的错误。如何解决此问题..请参阅下面的代码帮助我

在java.io.BufferedInputStream.streamClosed处(BufferedInputStream.java:118) 在java.io.BufferedInputStream.read处(BufferedInputStream.java:279)


如果联系人上没有照片,则返回的
InputStream
为空。在尝试解码图像之前,您应该检查
photo\u stream
是否为空

try {
        photo_stream = ContactsContract.Contacts
                .openContactPhotoInputStream(getActivity()
                        .getContentResolver(), contactPhotoUri);

        if(photo_stream != null) {
        buf_stream = new BufferedInputStream(photo_stream);

        cPhoto = BitmapFactory.decodeStream(buf_stream);
    }

    } catch (Exception e) {
        e.printStackTrace();
        }
也看看

try {
        photo_stream = ContactsContract.Contacts
                .openContactPhotoInputStream(getActivity()
                        .getContentResolver(), contactPhotoUri);

        if(photo_stream != null) {
        buf_stream = new BufferedInputStream(photo_stream);

        cPhoto = BitmapFactory.decodeStream(buf_stream);
    }

    } catch (Exception e) {
        e.printStackTrace();
        }