android开发 下载网络图片 每次 都不能成功?
urlstring="http://ww1.sinaimg.cn/bmiddle/6834c769jw1djjf4p3p9rj.jpg";URLurl=newURL(ur...
urlstring = "http://ww1.sinaimg.cn/bmiddle/6834c769jw1djjf4p3p9rj.jpg";
URL url = new URL(urlstring);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
InputStream is = conn.getInputStream();
每次执行到conn.getInputStream(),就抛出异常? 这个方法网络上大家都在用啊,为什么我在手机上测试的时候就不行? 而且访问网络的权限也给了?
希望高手帮忙指点哪里出错? 我想做的是,点击一个按钮,然后去网络上下载那张图片! 展开
URL url = new URL(urlstring);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
InputStream is = conn.getInputStream();
每次执行到conn.getInputStream(),就抛出异常? 这个方法网络上大家都在用啊,为什么我在手机上测试的时候就不行? 而且访问网络的权限也给了?
希望高手帮忙指点哪里出错? 我想做的是,点击一个按钮,然后去网络上下载那张图片! 展开
1个回答
展开全部
抛什么异常?不能try catch一下看看么
另外,你这个请求是不是新启动一个线程去做的,网络请求很耗时的
public InputStream getInputStream ()
Added in API level 1
Returns an InputStream for reading data from the resource pointed by this URLConnection. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.
Returns
the InputStream to read data from.
Throws
IOException
if no InputStream could be created.
参考
http://developer.android.com/reference/java/net/URLConnection.html#getInputStream()
另外,你这个请求是不是新启动一个线程去做的,网络请求很耗时的
public InputStream getInputStream ()
Added in API level 1
Returns an InputStream for reading data from the resource pointed by this URLConnection. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.
Returns
the InputStream to read data from.
Throws
IOException
if no InputStream could be created.
参考
http://developer.android.com/reference/java/net/URLConnection.html#getInputStream()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |