java.net.MalformedURLException: no protocol--Glide

no protocol翻译为无协议,像http/https都是最常用的指定协议,网络请求url格式不规范,就会造成该exception。
打印log:/storage/emulated/......的确是无协议,但是我就是加载本地图片的啊。
Glide图片加载库不仅可以加载网络资源也可以加载本地资源图片,但是为什么?

 public static void displayRound(Context context, ImageView imageView, String url) {
        if (imageView == null) {
            throw new IllegalArgumentException("argument error");
        }
        String cookie = SharedPreferencesUtil.getInstance().getString("cookie");
        GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder().addHeader("Set-Cookie", cookie).build());
        RequestOptions  requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.mipmap.ic_default_head)
                .error(R.mipmap.ic_default_head)
                .centerCrop()
                .fallback(new ColorDrawable(Color.RED))
                .transform(new GlideRoundTransformUtil())//圆角
        ;


        Glide.with(context).load(glideUrl)
                .apply(requestOptions)
                .into(imageView);

    }

简单看了看加载图片的代码,

 GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder().addHeader("Set-Cookie", cookie).build());

本公司后台需要保持个session会话,因为gilde不添加session会被拒绝访问,这段代码就是给glide添加session用的。

Glide.with(context).load(glideUrl)
                .apply(requestOptions)
                .into(imageView);

这里直接load(glideUrl),默认该请求为网络请求,所以加载本地图片资源时报了no protocol
重新起个方法加载就好:

 public static void displayLocalPic(Context context, ImageView imageView, String url) {
        if (imageView == null) {
            throw new IllegalArgumentException("argument error");
        }

        RequestOptions   requestOptions = new RequestOptions()
                .placeholder(new ColorDrawable(Color.BLACK))
                .error(new ColorDrawable(Color.BLUE))
                .centerCrop();

        Glide.with(context).load(url)
                .apply(requestOptions)
                .into(imageView);

    }

如果想了解Glide升级后其他的最基本的问题,可以参阅:https://blog.csdn.net/julystroy/article/details/84591378

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值