This question is about this popular Android library, Universal Image Loader for Android: https://github.com/nostra13/Android-Universal-Image-Loader
Image URL: http://i10.topit.me/l046/10046137034b1c0db0.jpg
Back trace:
01-14 00:24:42.125:
ERROR/ImageLoader(1671): http://i10.topit.me/l046/10046137034b1c0db0.jpg
java.io.FileNotFoundException: http://i10.topit.me/l046/10046137034b1c0db0.jpg
at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
at com.nostra13.universalimageloader.core.download.URLConnectionImageDownloader.getStreamFromNetwork(URLConnectionImageDownloader.java:40)
at com.nostra13.universalimageloader.core.download.ImageDownloader.getStream(ImageDownloader.java:27)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.saveImageOnDisc(LoadAndDisplayImageTask.java:296)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:204)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:128)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
Please help.
Follow up:
I finally solved my problem without changing one line of server code. What I did is replacing the default URLConnectionImageDownloader with HttpClientImageDownloader
Code sample:
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
// Default connection and socket timeout of 10 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
HttpClientParams.setRedirecting(params, false);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, "some_randome_user_agent");
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
ImageLoaderConfiguration config =
new ImageLoaderConfiguration
.Builder(MainActivity.sharedMainActivity.getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.discCache(new UnlimitedDiscCache(cacheDir))
.threadPoolSize(1)
.memoryCache(new WeakMemoryCache())
.imageDownloader(new HttpClientImageDownloader(new DefaultHttpClient(manager, params)))
.build();
:)
Look for implementation of libcore.net.http.HttpURLConnectionImpl.getInputStream()
@Override
public InputStream getInputStream() throws IOException {
if (!doInput) {
throw new ProtocolException("This protocol does not support input");
}
retrieveResponse();
/*
* if the requested file does not exist, throw an exception formerly the
* Error page from the server was returned if the requested file was
* text/html this has changed to return FileNotFoundException for all
* file types
*/
if (responseCode >= HTTP_BAD_REQUEST) {
throw new FileNotFoundException(url.toString());
}
if (responseBodyIn == null) {
throw new IOException("No response body exists; responseCode=" + responseCode);
}
return responseBodyIn;
}
According to this it can throw FileNotFoundException even if server error occurs or unauthorized.
I have not found value of HTTP_BAD_REQUEST but it's always was 400. Source code link http://www.java2s.com/Open-Source/Android/android-core/platform-libcore/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With