Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unterminated entity reference error

Tags:

android

I'm using google map route for my own android application. 2 days ago it worked well, but after that when the application runs its giving me errors via logcat. Can any body tell me a reason and solution for this problem.

org.xml.sax.SAXParseException: unterminated entity ref (position:ENTITY_REF &@1:799 in java.io.InputStreamReader@406cdeb0)

private String[] getDirectionData(String sourceLat, String sourceLong, String destinationLat, String destinationLong) {


 String urlString = "http://maps.google.com/maps?f=d&hl=en&" +"saddr="+sourceLat+","+sourceLong+"&daddr="+destinationLat+","+destinationLong + "&ie=UTF8&0&om=0&output=kml";
 Log.d("URL", urlString);
 Document doc = null;
 HttpURLConnection urlConnection = null;
 URL url = null;
 String pathConent = "";

 try {

  url = new URL(urlString.toString());
  urlConnection = (HttpURLConnection) url.openConnection();
  urlConnection.setRequestMethod("GET");
  urlConnection.setDoOutput(true);
  urlConnection.setDoInput(true);
  urlConnection.connect();
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  doc = db.parse(urlConnection.getInputStream());

 } catch (Exception e) {

     Log.w("Error in google map",e);
 }

 NodeList nl = doc.getElementsByTagName("LineString");
 for (int s = 0; s < nl.getLength(); s++) {
  Node rootNode = nl.item(s);
  NodeList configItems = rootNode.getChildNodes();
  for (int x = 0; x < configItems.getLength(); x++) {
   Node lineStringNode = configItems.item(x);
   NodeList path = lineStringNode.getChildNodes();
   pathConent = path.item(0).getNodeValue();
  }
 }
 String[] tempContent = pathConent.split(" ");
 return tempContent;
}
like image 861
Rajpirathap Sakthithasan Avatar asked Jul 29 '12 05:07

Rajpirathap Sakthithasan


3 Answers

In my case this problem appeared on a .png file inside /res/drawable folder. It is a bug, and it was reported here. So, for future reference, if you are facing it on a drawable, check that out. To summarize, update your ADT to, at least, the version 21.0.1.

like image 162
Eduardo Avatar answered Oct 21 '22 11:10

Eduardo


I have encountered the same problem. After debugging, I found that it was caused by the '&' character. it should be escaped

like image 35
suitianshi Avatar answered Oct 21 '22 09:10

suitianshi


I dont know sure but I think is because output=kml is not longer available a lot of users are having troubles with it.

like image 24
ƒernando Valle Avatar answered Oct 21 '22 10:10

ƒernando Valle