.gpx ファイルを解析して例外を受け取ります: 09-01 21:00:16.603: W/System.err(11762): org.xml.sax.SAXParseException: name expected (position:START_TAG @136:28 in java.io.InputStreamReader@41887c50)
ここに私の.gpxファイルがあります
<?xml version="1.0" encoding="utf-8"?>
<gpx><wpt>
<id>23512</id>
<lat>45.351486</lat>
<lon>36.474290</lon>
<name>Картинная галерея. г. Керчь</name>
</wpt><wpt>
<id>23512</id>
<lat>45.351486</lat>
<lon>36.474290</lon>
<name>Картинная галерея. г. Керчь</name>
</wpt><wpt>
<id>23436</id>
<lat>48.943566</lat>
<lon>34.185650</lon>
<name>Ветряк</name>
</wpt><wpt>
<id>23436</id>
<lat>48.943566</lat>
<lon>34.185650</lon>
<name>Ветряк</name>
</wpt>....
これが私のコードです:
List<Location> gpxList = null;
File gpxFile = new File(Environment.getExternalStorageDirectory()
+ "/Shukach/shukach.gpx");
gpxList = decodeGPX(gpxFile);
方法:
private List<Location> decodeGPX(File file) {
List<Location> list = new ArrayList<Location>();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
.newInstance();
try {
DocumentBuilder documentBuilder = documentBuilderFactory
.newDocumentBuilder();
FileInputStream fileInputStream = new FileInputStream(file);
Document document = documentBuilder.parse(fileInputStream);
Element elementRoot = document.getDocumentElement();
NodeList nodelist_wpt = elementRoot.getElementsByTagName("wpt");
for (int i = 0; i < nodelist_wpt.getLength(); i++) {
Node node = nodelist_wpt.item(i);
NamedNodeMap attributes = node.getAttributes();
String newLatitude = attributes.getNamedItem("lat")
.getTextContent();
Double newLatitude_double = Double.parseDouble(newLatitude);
String newLongitude = attributes.getNamedItem("lon")
.getTextContent();
Double newLongitude_double = Double.parseDouble(newLongitude);
String newLocationName = newLatitude + ":" + newLongitude;
Location newLocation = new Location(newLocationName);
newLocation.setLatitude(newLatitude_double);
newLocation.setLongitude(newLongitude_double);
list.add(newLocation);
Log.d(TAG, newLocationName);
}
fileInputStream.close();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
問題が理解できず、インターネットで解決策を見つけることができません...助けてください。