6

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;
}
competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • add some of your code and image address to your question – hasanghaforian Jul 29 '12 at 06:00
  • oh, found perfect answer in this forum [Link to matching answer][1] [1]: http://stackoverflow.com/questions/11745314/why-retrieving-google-directions-for-android-using-kml-data-is-not-working-anymo – 2red13 Nov 27 '12 at 15:41

6 Answers6

7

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.

Eduardo
  • 4,282
  • 2
  • 49
  • 63
  • 9
    Your problem can be solved by cleaning your project build (Project | Clean... | and select your project to clean). – Aryo Jan 09 '13 at 12:38
  • Thanks this helped me. If the clean project does not work then try to open one .png file by right clicking it and choose "open with - in place editor". After closing the editor window the errors where gone. – Punit Raizada Mar 12 '13 at 16:12
3

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

suitianshi
  • 3,300
  • 1
  • 17
  • 34
1

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

ƒernando Valle
  • 3,634
  • 6
  • 36
  • 58
  • http://stackoverflow.com/questions/11745314/why-retrieving-google-directions-for-android-using-kml-data-is-not-working-anymo – 2red13 Dec 05 '12 at 07:21
  • if you write a link in your browser, the kml thing simply works well. This suggests that there is some problem with the coding. I am facing the same problem, same code, but i wasnt sure if it gave an output some days before. – 10101010 Dec 20 '12 at 09:58
0

The error message is pretty suggestive: The ref tag is unterminated, e.g. the <ref> doesn't have an enclosing </ref> pair. Validate your XML input with a tool like this.

overbet13
  • 1,654
  • 1
  • 20
  • 36
  • 1
    not useful, the problem is clear, but the response is validated by google and the code is indeed not running since june. I'm searching for the same issue – 2red13 Nov 27 '12 at 13:50
  • @2red13 whats your take on my answer ? – 10101010 Jan 03 '13 at 09:20
0

I was myself facing the same problem. This exception is coming because some important KML elements have been deprecated by google recently. For example, refer GeometryCollection . If your code tries to find any such elements in the received document, it might throw an SAXParseException: unterminated entity ref .

They have introduced a new API for Maps. It is available here .

I myself downloaded the kml file, and stored it in the device. When I had a look at it using the editor, I did not find the element my code was looking for. However, if you use the kml file to find a route in the latest Chrome Version, it works.

10101010
  • 607
  • 8
  • 24
0

I got the same problem. It was in a .png image file. The problem occurred after I edited the file. I searched for the solution but after that I cleaned my project using "clean.." option under "project" tab. SO finally I got rid of that "

Vikrant_Dev
  • 430
  • 2
  • 15