问题描述
- 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;
解决方案
close项目,重新打开试试,或者关闭eclipse,再开。
时间: 2024-12-23 00:33:43