android 中使用.Glide加载图片无效,该怎么解决?
public View getView(int position, View view, ViewGroup parent) {
if (view==null) {
view = LayoutInflater.from(getContext()).inflate(resource, parent, false);
}
News news=getItem(position);
ImageView imageView=view.findViewById(R.id.lv_image);
TextView name=view.findViewById(R.id.lv_title);
TextView from=view.findViewById(R.id.lv_from);
TextView time=view.findViewById(R.id.lv_time);
TextView read_num=view.findViewById(R.id.lv_read_num);
String s="http:"+news.getPic();
Log.v("ssss",s);
Glide.with(view.getContext()).load(s).into(imageView);
name.setText(news.getName());
from.setText(news.getFrom());
time.setText(news.getTime());
read_num.setText(news.getRead_num());
return view;
}
报错
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 2 causes:
java.io.IOException(Cleartext HTTP traffic to image2.thepaper.cn not permitted)
java.io.FileNotFoundException(No content provider: http://image2.thepaper.cn/image/40/838/183.jpg)
大佬们,该怎么解决
Picasso.with(view.getContext()).load(s).into(imageView);
这里load只能是本地路径,不能是url
你得用httpclient先下载文件到本地,再用本地的文件名去load
--_-- 你到底用的是Glide还是Picasso
你先输出下url,然后在PC上打开是否有图片
再去找找,试试看IOException(Cleartext HTTP traffic to image2.thepaper.cn not permitted)的解决办法
https://www.jianshu.com/p/2e3ca44cf7be
http拒绝,应该是Android9的问题,网上有配置,res和metfist里面配置
两个方面,第一个,你的上下文context的问题,换成从getContext(),第二个Android9.0不允许http访问,你可以配置过滤。