ImageLoader:连接超时

时间:2017-11-15 14:52:50

标签: java android imageloader

我正在使用ImageLoader从互联网上加载图片。但是我收到错误消息“E ImageLoader:connect timed out”,跟踪是:

  

05-29 16:39:02.994 9988 10417 E ImageLoader:连接超时05-29   16:39:02.994 9988 10417 E ImageLoader:   java.net.SocketTimeoutException:connect timed out 05-29 16:39:02.994   9988 10417 E ImageLoader:at   java.net.PlainSocketImpl.socketConnect(Native Method)05-29   16:39:02.994 9988 10417 E ImageLoader:at   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)05-29   16:39:02.994 9988 10417 E ImageLoader:at   java.net.Socket.connect(Socket.java:605)05-29 16:39:02.994 9988   10417 E ImageLoader:at   com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.Connection.connectSocket(Connection.java:196)05-29   16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.Connection.connect(Connection.java:172)05-29   16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.OkHttpClient $ 1.connectAndSetOwner(OkHttpClient.java:130)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:247)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:480)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:428)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:544)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromNetwork(BaseImageDownloader.java:117)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:88)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.decode.BaseImageDecoder.getImageStream(BaseImageDecoder.java:98)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:74)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:265)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:238)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:136)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:607)   05-29 16:39:02.994 9988 10417 E ImageLoader:at   java.lang.Thread.run(Thread.java:761)05-29 16:39:02.995 9988 9988 D   TweetAdapter:onLoadingFailed,uri是   https://lh6.googleusercontent.com/-55osAWw3x0Q/URquUtcFr5I/AAAAAAAAAbs/rWlj1RUKrYI/s1024/A%252520Photographer.jpg,   failReason IO_ERROR

以下是我的代码:

private DisplayImageOptions mOptions;
mOptions = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.mipmap.ic_launcher)
            .showImageOnFail(R.mipmap.ic_launcher)
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .build();
mConfig = new ImageLoaderConfiguration.Builder(context)
            .defaultDisplayImageOptions(mOptions)
            .discCacheSize(50 * 1024 * 1024)
            .discCacheFileCount(100)
            .writeDebugLogs().build();
ImageLoader.getInstance().init(mConfig);

ViewHolder的定义是:

private static class ViewHolder {
    ImageView imageButtonSender;
    TextView textViewSenderUserName;
    TextView textViewSenderContent;
    FrameLayout frameLayoutImages;
    LinearLayout linearLayoutCommentContent;
}

在我的适配器的“getView”函数中,我调用了这个函数:

ImageLoader.getInstance().loadImage("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQW0S4wK02z4QilNvGE9YFtoJDJtbTsoZavc3INxbD9ZvdRgfxy",
             new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String imageUri, View view) {

                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    Log.d(TAG, "onLoadingFailed, uri is " + imageUri + ", failReason " + failReason.getType());
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    Log.d(TAG, "onLoadingComplete imageUri " + imageUri);
                    holder.imageButtonSender.setImageBitmap(loadedImage);
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {

                }
            });

我尝试了其他网址,例如“https://lh6.googleusercontent.com/-55osAWw3x0Q/URquUtcFr5I/AAAAAAAAAbs/rWlj1RUKrYI/s1024/A%252520Photographer.jpg”,但同样的错误再次发生。

谁能帮帮我?

1 个答案:

答案 0 :(得分:1)

解决方案:我的手机无法访问需要国际互联网许可的这两个网址,但我的电脑可以