Java 为什么我无法从imageUrl获取imageview中的图像?
我想在Java 为什么我无法从imageUrl获取imageview中的图像?,java,android,Java,Android,我想在ImageView中显示一个图像,该图像是从我在函数中指定的url获取的。下面是我试图获取图像的函数 public Bitmap getBitmapFromUrl(String src){ try{ URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInpu
ImageView
中显示一个图像,该图像是从我在函数中指定的url获取的。下面是我试图获取图像的函数
public Bitmap getBitmapFromUrl(String src){
try{
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
Bitmap btmp = BitmapFactory.decodeStream(inputStream);
return btmp;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
上述函数正在返回null
。参数src
“”
请帮帮我。我错在哪里?在显示url中的图像时,最好使用Glide或Picasso之类的库,而不是使用此库。。。检查logcat…发布您的错误stacktrace。您是否在清单中添加了internet权限?此外,您可能希望将代码放入异步调用中……虽然这可能是真的,但它并没有解释上述代码的错误。