doInBackground执行报错
完全按照视频在AS下写的,但一运行就报错,提示java.lang.RuntimeException: An error occured while executing doInBackground(),关键就是is = connection.getInputStream()这句不知有什么问题。
protected Bitmap doInBackground(String... strings) {
//获取传递进来的参数
String url = strings[0]; //取出对应url
Bitmap bitmap = null;
URLConnection connection; //定义网络连接对象
InputStream is; //用于获取数据的输入流
try {
connection = new URL(url).openConnection(); //获取网络连接对象
is = connection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bitmap = BitmapFactory.decodeStream(bis); //将输入流解析成bitmap
is.close();
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}