无法从Android上我的本地服务器加载图像 [英] Can't load image from my local server on Android

查看:233
本文介绍了无法从Android上我的本地服务器加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从服务器加载图像来显示它在ImageView的

I am trying to load an image from a server to show it in an ImageView

我用

    ImageView imgView = (ImageView) findViewById(R.id.ivProduct);

    Bitmap bitmap = null;

    try {

        URL urlImage = new URL(
                "http://www.google.fr/intl/en_com/images/srpr/logo1w.png");
        HttpURLConnection connection = (HttpURLConnection) urlImage
                .openConnection();
        InputStream inputStream = connection.getInputStream();
        bitmap = BitmapFactory.decodeStream(inputStream);
        imgView.setImageBitmap(bitmap);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}`

这工作得很好,但是当我下载了相同的图像我的服务器上,我改变了网址

This worked fine but when I downloaded the same image on my server and I changed the url to

http://localhost:9527/market_helper/img_products/logo1w.png

它没有工作。
有什么问题?

It did not work. What is the problem ?

推荐答案

的问题是,在您的网址中的http://本地主机:9527说,这是你的本地计算机上的服务器上运行,但访问时在Android中的http:// localhost的,指的是设备本身

The problem is that in your url the "http://localhost:9527" says it is running on a server on your local machine, but when accessing from your Android the "http://localhost" refers to the device itself.

如果你是在同一个网络上,你可以尝试用你的电脑的本地IP地址替换localhost的部分(例如192.168.100.6)访问它,你可以找到你的IP是由下键入ipconfig,在命令行。

If you are on the same network you can try access it by replacing the "localhost" part with your PC's local ip address (for example 192.168.100.6) You can find out what your IP is by typing "ipconfig" in the commandline.

这篇关于无法从Android上我的本地服务器加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆