Android Universal Image Loader会出现错误java.net.SocketException

时间:2014-07-28 12:06:49

标签: android universal-image-loader socketexception

我在我的应用程序中使用通用图像加载器,它在仿真器上的工作也很好,三星不是2,但它在其他设备中出错

在图像显示类

private ImageLoadingListener imageLoadingListener = new ImageLoadingListener();

private class ImageLoadingListener extends SimpleImageLoadingListener {

    public void onLoadingComplete(String imageUri, View view,
            Bitmap loadedImage) {
        if (loadedImage == null) {
            articleImage.setVisibility(View.GONE);
            imgDesc.setVisibility(View.GONE);
        }
    }
}

 AppClass.getImageLoader().displayImage(url,imageview,AppClass.getDisplayImageOptions(), imageLoadingListener);

在AppClass中

public class AppClass extends Application {

    protected static ImageLoader imageLoader = ImageLoader.getInstance();

     public static ImageLoader getImageLoader() {
    return imageLoader;
  }

public static void initImageLoader(Context context) {
    // This configuration tuning is custom. We can tune every option, you may tune some of them,
    // or you can create default configuration by
    // ImageLoaderConfiguration.createDefault(this);
    // method.
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            .writeDebugLogs() // Remove for release app
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);
}

public static DisplayImageOptions getDisplayImageOptions() {
    boolean isExternalStorageWritable = Util.isExternalStorageWritable();
    SMLog.d(tag, "getDisplayImageOptions()isExternalStorageWritable="+isExternalStorageWritable);


    return new DisplayImageOptions.Builder()
            /*.showImageOnLoading(R.drawable.ic_no_image)
            .showImageForEmptyUri(R.drawable.ic_no_image)
            .showImageOnFail(R.drawable.ic_no_image)*/
            .cacheInMemory(!isExternalStorageWritable)
            .cacheOnDisc(isExternalStorageWritable)
            .considerExifParams(false).bitmapConfig(Bitmap.Config.RGB_565)
            .build();
  }
}

日志

07-28 17:13:14.010: E/ImageLoader(29835): recvfrom failed: ECONNRESET (Connection reset by peer)
07-28 17:13:14.010: E/ImageLoader(29835): java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:559)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.IoBridge.recvfrom(IoBridge.java:523)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.io.InputStream.read(InputStream.java:163)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.io.BufferedInputStream.read(BufferedInputStream.java:227)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.Streams.readAsciiLine(Streams.java:201)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
07-28 17:13:14.010: E/ImageLoader(29835):   at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromNetwork(BaseImageDownloader.java:115)
07-28 17:13:14.010: E/ImageLoader(29835):   at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:86)
07-28 17:13:14.010: E/ImageLoader(29835):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:290)
07-28 17:13:14.010: E/ImageLoader(29835):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisk(LoadAndDisplayImageTask.java:273)
07-28 17:13:14.010: E/ImageLoader(29835):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:229)
07-28 17:13:14.010: E/ImageLoader(29835):   at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:135)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-28 17:13:14.010: E/ImageLoader(29835):   at java.lang.Thread.run(Thread.java:856)
07-28 17:13:14.010: E/ImageLoader(29835): Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.Posix.recvfromBytes(Native Method)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.Posix.recvfrom(Posix.java:131)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
07-28 17:13:14.010: E/ImageLoader(29835):   at libcore.io.IoBridge.recvfrom(IoBridge.java:520)
07-28 17:13:14.010: E/ImageLoader(29835):   ... 20 more

0 个答案:

没有答案