Creating url string to get icon in java

I am trying to get an icon from a website with the following method. I tried to avoid // problems and decided to use a URL object.

 public static Bitmap getBitmapFromURL(URL src) {
        try {
            URL url = src;
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

I run

Bitmap faviconBitmap = getBitmapFromURL(new URL("http", "www"+url, "/favicon.ico"));

with my url set to: url = imdb.com

but I fail and get the following error:

01-24 20:01:33.702: W/System.err(8678): java.io.IOException: Illegal character in authority at index 22: http://www.nytimes.com
01-24 20:01:33.702: W/System.err(8678): /favicon.ico

Any suggestions to fix this?

+5
source share
1 answer

It looks like you have a newline or some other character at the end urlafter "nytimes.com".

+2
source

All Articles