I’m trying to get xml data and parse it with an async task. Here is what I did :
In OnCreate method I get url as string. I tested my url and it doesn’t return null. Also has permission to connect to Internet.
startDownload start = new startDownload();
start.execute(url.toString());
And my Async class :
protected class startDownload extends AsyncTask<String, Void, String>{
@Override
protected void onPreExecute() {
eczaDialog = ProgressDialog.show(ListViewXML.this,"", "Loading...");
}
@Override
protected String doInBackground(String... aurl) {
try {
URL url = new URL(aurl[0]);
DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize(); ....
When i debug my code i saw that this doc variable returned null. I don’t understand where was the problem. I hope you can help me to find out Thanks.
You have to get the content of the xml. You can use this, the code returns the content in the string, after you can create an XML object :