【问题标题】:Universal Image Loader not working通用图像加载器不工作
【发布时间】:2013-08-27 09:39:41
【问题描述】:

我正在尝试使用通用图像加载器,但我遇到了一个奇怪的问题。 我的应用程序无法加载图像。它记录了一个错误,即“无法解析主机“baodientu.chinhphu.vn”:没有与主机名关联的地址” 即使我尝试添加另一个示例代码(我从https://github.com/nostra13/Android-Universal-Image-Loader 签出),它仍然没有显示。 但我在浏览器中尝试了这个 url。它被显示。 我的网址是http://baodientu.chinhphu.vn/uploaded_vgp/dangdinhnam/20130626/nguoi%20lao%20dong.jpg 请帮我找出原因。

【问题讨论】:

  • 你试过其他网址吗?
  • 是的,我试过了,但还是没有运气:(

标签: android universal-image-loader


【解决方案1】:

这不是 ImageLoader 的问题。它是您的服务器端的问题。

服务器关闭或主机名可能错误或您无法授予 Internet 访问权限..

所以尝试为你的清单文件添加权限:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

【讨论】:

    【解决方案2】:

    如果您的许可是正确的。请检查您设备中的网络是否正常工作,这取决于您使用的连接 api (URLConnection || HttpURLConnection)。尝试使用以下代码

    InputStream stream = null;
        try {
            URLConnection conn = new URL(url).openConnection();   
    
            if (conn instanceof HttpURLConnection){
                try {
                    HttpURLConnection httpConn = (HttpURLConnection) conn;
                    httpConn.setAllowUserInteraction(false);
                    httpConn.setInstanceFollowRedirects(true);
                    httpConn.setRequestMethod("GET");
                    httpConn.connect();
    
                    response = httpConn.getResponseCode();
                    if (response == HttpURLConnection.HTTP_OK) {
                        stream  = httpConn.getInputStream();
                    }
                } catch (Exception ex) {
                    throw new IOException("Unable to create InputStream for image Url:");
                }
            }else{
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.connect();
                stream = conn.getInputStream();
            }
            if (stream == null) {
                Log.e(getClass().getName(), "Unable to create InputStream for image Url:" + url);
            }
    

    【讨论】:

      【解决方案3】:

      在你的清单文件中添加这两个权限

      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      

      您可以使用此代码加载图像

      URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
      Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
      imageView.setImageBitmap(bmp);
      

      你也可以参考这个链接

      www.androidhive.info/2012/07/android-loading-image-from-url-http/

      【讨论】:

      • 我正在发布我在下面设置的权限:' '
      【解决方案4】:

      添加到 AndroidManifest.xml 中

      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      

      添加到您的代码中。

      ImageLoader imgLoader = ImageLoader.getInstance();
      imgLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext()));
      imgLoader.displayImage(YourImageURL.toString(), YourImageView);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-29
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-15
        相关资源
        最近更新 更多