android中可用图像的FileNotFoundException?

时间:2011-07-13 02:48:09

标签: android file downloading

我正在尝试在位图http://img.youtube.com/vi/rzqqrYLARCE/1.jpg中读取此文件。 在普通的PC浏览器上它显示相同,但​​当我以Bitmap形式阅读它时,它显示我“ FileNot Found Exception“

这是我的logcat:

375,145


07-13 08:05:38.760: WARN/System.err(1383): java.io.FileNotFoundException: 
07-13 08:05:38.760: WARN/System.err(1383): java.io.FileNotFoundException: http://img.youtube.com/vi/rzqqrYLARCE/1.jpg
07-13 08:05:38.770: WARN/System.err(1383):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
07-13 08:05:38.770: WARN/System.err(1383):     at com.andro.iparty.data.Util.getBitmapFromURL(Util.java:39)
07-13 08:05:38.770: WARN/System.err(1383):     at com.andro.iparty.VideoGallery$2.run(VideoGallery.java:161)
07-13 08:05:38.770: WARN/System.err(1383):     at java.lang.Thread.run(Thread.java:1058)

我的编码方法是:

public static Bitmap getBitmapOrignalSizeFromURL(String src) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);

            return myBitmap;


            // return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

请告诉我文件扩展名(jpg)是否有任何问题。

感谢所有

1 个答案:

答案 0 :(得分:1)

看看这个类似问题的解决方案,尝试过,它有效

Download an image from the web