2 weekyyu weekyyu 于 2014.12.01 22:05 提问

android开发中url的openConnection()不能被IDE识别怎么办?

new AsyncTask() {
@Override
protected String doInBackground(String... params) {
try {
URI url = new URI(params[0]);
URLConnection connection=url.openConnection();//这行的openConnection显示为红色
long total = connection.getContentLength();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
StringBuilder sb = new StringBuilder();
while ((line=br.readLine())!=null){
sb.append(line);
publishProgress((float)sb.toString().length()/total);
}
br.close();
is.close();
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;

1个回答

guwei4037
guwei4037   Ds   Rxr 2014.12.01 23:04

close项目,重新打开试试,或者关闭eclipse,再开。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!