Search code examples
androiduniversal-image-loader

Universal Image Loader custom ImageDownloader


I've implemented a custom BaseImageDownloader, and it's method InputStream getStreamFromOtherSource(String imageUri, Object extra).

Everything works ok.

The thing is, some times, the file I'm opening is corrupt (out of my hands, it might happen) and I can detect when it does happen. Right now I'm returning null, and it produces a null pointer exception

ERROR/ImageLoader(21847): null
    java.lang.NullPointerException
    at com.nostra13.universalimageloader.utils.IoUtils.copyStream(IoUtils.java:39)

It does not break anything, since it's not closing the app, and the "fail" image is properly shown, I just don't like it throwing an exception.

Is there a proper way to handle this?


Solution

  • You could edit the ImageLoader code where the error is caused, but there is really no purpose for that. What is happening is exactly what exceptions were made for; errors that are expected to occur occasionally, but at unpredictable times. That's why you handle it with a try/catch block...