In my Android application I need to load and show images from internet so that I use Universal Image loader library to load images. In the application I get image links from json (some urls do not have images in server). My problem is the universal image loader throws the FailType.IO_ERROR (fail reason) for both internet problem or the file is not found in the server, How can I differentiate between internet problem and File not found in the server?, because I need to show alert only if problem occur by file is not found in the server not by internet problem in the FailType.IO_ERROR (fail reason) category.
This is the code I used for image loading:
imageLoader.displayImage(linkOfImage, imageView, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String arg0, View arg1) {
}
@Override
public void onLoadingFailed(String arg0, View arg1,
FailReason failed) {
FailType failType = failed.getType();
int failedCode = failType.ordinal();
if (failedCode == FailType.IO_ERROR.ordinal()) {
// I reach here for both internet and file not found in the server
}else if (failedCode == FailType.DECODING_ERROR.ordinal()) {
} else if (failedCode == FailType.NETWORK_DENIED.ordinal()) {
} else if (failedCode == FailType.OUT_OF_MEMORY.ordinal()) {
} else if (failedCode == FailType.UNKNOWN.ordinal()) {
}
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
// ...........
}
@Override
public void onLoadingCancelled(String arg0, View arg1) {
}
});
I listed all FailReason type. I get error code 0 (FailType.IO_ERROR) for both if the image is not present in the server for a particular link or internet is not present.
Please help me to find out the difference between two exceptions, this task is importance to me. thanks in Advance.
You can get thrown exception by
failReason.getCause()
.So then you can check
failReason.getCause() instanceof FileNotFoundException
orfailReason.getCause() instanceof SocketTimeoutException
. Something like that.