求救啊安卓connection调用getInputStream()就出错,connection不是空的
publicBitmapgetBitmapFromURL(StringurlString){Bitmapbitmap;InputStreamis=null;try{URL...
public Bitmap getBitmapFromURL(String urlString){
Bitmap bitmap ;
InputStream is=null ;
try {
URL url=new URL(urlString);
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
InputStream ins=connection.getInputStream();
is=new BufferedInputStream(connection.getInputStream());
bitmap=BitmapFactory.decodeStream(is);
connection.disconnect();
return bitmap;
} catch (java.io.IOException e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
} 展开
Bitmap bitmap ;
InputStream is=null ;
try {
URL url=new URL(urlString);
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
InputStream ins=connection.getInputStream();
is=new BufferedInputStream(connection.getInputStream());
bitmap=BitmapFactory.decodeStream(is);
connection.disconnect();
return bitmap;
} catch (java.io.IOException e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
} 展开
展开全部
你可以直接URL.getInputStream呀,为什么要getConnection再去getinputstrem呢,多此一举呀,再说你getconnection之后为什么要把他强转为httpUrlconnection呢?你又没有用HttpUrlConnetion里的方法,直接用UrlConnection这个类也是可以的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询