In one of my android app when I am trying to parse an xml file from some url , sometimes i get ParseException: At line 1, column 0: no element found SAXException but the strange thing is I dont get this exception always means when I refresh the page again (going back to previous activity and coming again ) It starts working (means it parse the xml).
I could not find the exact reason why this is happening. It seems to me that It might be the problem of internet but the net is working on device and one more thing it does not happened always some time its prases the XML easily but sometimes it throws the exception.
Here is the code i am using for parsing :
xr.parse(new InputSource(new URL(urlToHit).openStream()));
I have tried another way also for parsing :
URL serverAdd=new URL(urlToHit);
URLConnection connection = serverAdd.openConnection();
xr.parse(new InputSource(connection.getInputStream()));
But the problem still continues.(Sometimes it parses the xml sometimes it cannot)
Please help as its very urgent for me .
Thanks.