Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在android图像视图中显示tomcat中本地服务器的图像_Java_Android - Fatal编程技术网

Java 如何在android图像视图中显示tomcat中本地服务器的图像

Java 如何在android图像视图中显示tomcat中本地服务器的图像,java,android,Java,Android,我正在尝试在android图像视图中设置图像。 我使用以下代码在图像视图中设置图像: Bitmap bmImg = BitmapFactory.decodeFile("http://172.22.30.55:8080/data/product_images/"+data.get("col_1")); imageView =(ImageView)view.findViewById(R.id.product_image); imageView.setImageBitmap(bmImg); 但我得到

我正在尝试在android图像视图中设置图像。 我使用以下代码在图像视图中设置图像:

Bitmap bmImg = BitmapFactory.decodeFile("http://172.22.30.55:8080/data/product_images/"+data.get("col_1"));
imageView =(ImageView)view.findViewById(R.id.product_image);
imageView.setImageBitmap(bmImg);
但我得到了以下例外:

 E/BitmapFactory(3663): Unable to decode stream: java.io.FileNotFoundException: /http:/172.22.30.55:8080/data/product_images/056075419be6ed982cb63eba81056396.png: open failed: ENOENT (No such file or directory)
我试图做的是从本地服务器获取映像文件,但使用的是我的代码

我犯了什么错误?

试试这个:

     ImageView imageview= (ImageView)view.findViewById(R.id.product_image);

        try{
            String url = "http://172.22.30.55:8080/data/product_images/"+data.get("col_1");
            URL ulrn = new URL(url);
            HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
            InputStream is = con.getInputStream();
            Bitmap bmp = BitmapFactory.decodeStream(is);
            if (null != bmp)
                imageview.setImageBitmap(bmp);
            else
                System.out.println("Bitmap is NULL");

                 if (con != null) {   
                      con.disconnect();  
                  } 
        } catch(Exception e) {
        }  
试试这个:

     ImageView imageview= (ImageView)view.findViewById(R.id.product_image);

        try{
            String url = "http://172.22.30.55:8080/data/product_images/"+data.get("col_1");
            URL ulrn = new URL(url);
            HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
            InputStream is = con.getInputStream();
            Bitmap bmp = BitmapFactory.decodeStream(is);
            if (null != bmp)
                imageview.setImageBitmap(bmp);
            else
                System.out.println("Bitmap is NULL");

                 if (con != null) {   
                      con.disconnect();  
                  } 
        } catch(Exception e) {
        }  

使用毕加索从网络加载图像。你只需要写在下面几行

String url = "http://172.22.30.55:8080/data/product_images/"+data.get("col_1");
imageView =(ImageView)view.findViewById(R.id.product_image);
Picasso.with (YourActivity.this)
                    .load(Uri.parse(url))
                    .into(imageView);

您还需要在清单中提供INTERNET权限,并在构建中添加毕加索的依赖项。gradle

使用毕加索从网络加载图像。你只需要写在下面几行

String url = "http://172.22.30.55:8080/data/product_images/"+data.get("col_1");
imageView =(ImageView)view.findViewById(R.id.product_image);
Picasso.with (YourActivity.this)
                    .load(Uri.parse(url))
                    .into(imageView);


您还需要在清单中提供INTERNET权限,并在构建中添加毕加索的依赖项。gradle

172.0.0
是网络地址,很可能不是服务器的实际ip地址。我知道。但在我的代码中,我使用的是正确的IP。将此作为一天中的示例课程:如果您提供非工作代码,您会导致希望帮助您的人走上错误的道路,他们会解决与您的实际问题无关的问题。始终发布一个.Updated我的问题。如果不看文档,我的猜测是:
BitmapFactory.decodeFile()
函数无法处理http URL,它在本地文件系统上查找文件,但找不到。
172.0.0.0
是网络地址,这很可能不是您服务器的实际ip地址。我知道。但在我的代码中,我使用的是正确的IP。将此作为一天中的示例课程:如果您提供非工作代码,您会导致希望帮助您的人走上错误的道路,他们会解决与您的实际问题无关的问题。始终发布.Updated my question。如果不看文档,我的猜测是:
BitmapFactory.decodeFile()
函数无法处理http URL,它在本地文件系统上查找文件,但找不到。虽然这很可能解决问题,但我已经看到下一个异常出现。虽然这很可能解决问题,但我已经看到下一个异常出现。您使用的是android studio还是eclipse?在这种情况下,您需要为毕加索添加jar文件您的项目。您可以从这里下载repo1.maven.org/maven2/com/squareup/picasso/picasso/2.5.2/picasso-2.5.2.jarcopy将此jar文件粘贴到您的项目libs/folder是否使用android studio或eclipse?在这种情况下,您需要将毕加索的jar文件添加到您的项目中。您可以从这里下载它repo1.maven.org/maven2/com/squareup/picasso/picasso/2.5.2/picasso-2.5.2.jarcopy将此jar文件粘贴到项目库/文件夹中