据说高版本的Android不能在UI主线程里面执行下载网络数据的请求,那本人将此功能重新开辟了一个线程,为什么执行到红色代码行时还是有异常,求大牛帮看看,感激不尽
Runnable HttpDownload = new Runnable(){
Runnable HttpDownload = new Runnable(){
public void run(){
System.out.println(“thread has been started…..”);
try{
URL url = new URL(“http://192.168.1.153:8080/mp3/resource.xml”);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
buffer = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
while ( (line = buffer.readLine()) != null)
{
sb.append(line);
}
解决方案
40
最好调用一下connection.connect(),否则有些手机会异常。