Question: I'm getting a MalformedURLException some code in my Android Studio project. My aim is to get and display an image from a web page, and the URL seems to be fine, but it's giving me this error.

I have already put the code in a `try`,`catch`, but that is still giving me the error.
Here is the code to grab the image and display it:

```
    try
    {
        url = new URL(items.get(position).getLink());
        bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    }
    catch (IOException e)
    {
        throw new RuntimeException("Url Exception" + e);
    }

    holder.itemTitle.setText(items.get(position).getTitle());;
    holder.itemHolder.setBackgroundDrawable(new BitmapDrawable(bmp));

```

`items.get(position).getLink()` is meant to get the link that is being displayed in a `ListView`, but even something like `URL url = new URL("https://www.google.com")` doesn't work.

Thanks.

Answer: 
your url is [formatted without the protocol at the beginning](http://developer.android.com/reference/java/net/URL.html) try

```
url = new URL("http://"+items.get(position).getLink());

```

sometimes the url string may have special characters, in which case you need to [encode it properly please see this](https://stackoverflow.com/questions/573184/java-convert-string-to-valid-uri-object).
And also, the url you posted in the comment is not an image.
Just click alt+enter and then import try catch section... this helped me...