从给定的URL获取位图图像显示java.io.FileNotFoundException

时间:2014-06-11 15:41:14

标签: android inputstream filenotfoundexception android-bitmap

在我的android项目中,我想从given URL(htp://....)获取一个Bitmap图像,为此我使用下面的代码来实现这个概念。但是在运行我的代码时,我得到java.io.FileNotFoundException。所以任何人都应该提供更好的解决方案来解决这个问题,或者提供任何代码片段来实现这个任务。

public static Bitmap getBitmapFromURL(String src) {
        try {
            Log.e("src", src);
            String stringURL = "http://.....";          
            URL url = new URL(stringURL);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            Log.e("Bitmap", "returned");
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("Exception", e.getMessage());
            return null;
        }
    }

0 个答案:

没有答案