I want to read a XML document from a URL:
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();
}
I get an Error Exception
android.os.NetworkOnMainThreadException
I added uses-permission in manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
This is not an XML Problem its a Strict Mode Problem.
You should’nt do time intensiv things in Gui Thread, do it in a own Thread.
However, you can disable it, but you shouldt 😉
see here