我想从URL读取 XML 文档:
public void DownloadXmlFile() throws IOException{
//TODO
String url = "http://api.m1858.com/coursebook.xml";
URL u = new URL(url);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
}
我得到一个错误异常
android.os.NetworkOnMainThreadException
我在清单文件中添加了使用权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />