为什么我得到" java.net.MalformedURLException:未找到协议"?

时间:2014-07-08 01:11:14

标签: java android

@Override
    protected Drawable doInBackground(String... params) {
        try{
            String url = params[0].replace("\\", "");
            Log.v("before", params[0]);
            Log.v("after", url);
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        }catch (Exception e) {
            Log.e("Image Error", e.toString());
            return null;
        }
    }
  

7-07 22:02:03.282:之前(21811):   “https://s3-sa-east-1.amazonaws.com/inradar.media/uploads/ads/ad-60cd15be59b21725e45c5cf388065527.jpg”

     

07-07 22:02:03.282:之后(21811):   “https://s3-sa-east-1.amazonaws.com/inradar.media/uploads/ads/ad-60cd15be59b21725e45c5cf388065527.jpg

     

07-07 22:02:03.282:图像错误(21811):   java.net.MalformedURLException:找不到协议:   “https://s3-sa-east-1.amazonaws.com/inradar.media/uploads/ads/ad-60cd15be59b21725e45c5cf388065527.jpg

1 个答案:

答案 0 :(得分:3)

我不知道任何记录器会在给定的日志消息中添加封闭引号。因此,我将假设您的url String确实是

"https://s3-sa-east-1.amazonaws.com/inradar.media/uploads/ads/ad-60cd15be59b21725e45c5cf388065527.jpg"

URL构造函数无法解析该值。摆脱前导和尾随的引号。