Java Can';无法找到此异常的解决方案:org.xml.sax.SAXParseException:name预期(位置:START_TAG<;null>@
我正在解析.gpx文件并接收异常: 09-01 21:00:16.603:W/System.err(11762):org.xml.sax.SAXParseException:应为名称(位置:java.io中的START_TAG@136:28)。InputStreamReader@41887c50) 这是我的.gpx文件Java Can';无法找到此异常的解决方案:org.xml.sax.SAXParseException:name预期(位置:START_TAG<;null>@,java,android,Java,Android,我正在解析.gpx文件并接收异常: 09-01 21:00:16.603:W/System.err(11762):org.xml.sax.SAXParseException:应为名称(位置:java.io中的START_TAG@136:28)。InputStreamReader@41887c50) 这是我的.gpx文件 <?xml version="1.0" encoding="utf-8"?> <gpx><wpt>
<?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>....
23512
45.351486
36.474290
Картинная галерея. г. Керчь
23512
45.351486
36.474290
Картинная галерея. г. Керчь
23436
48.943566
34.185650
Ветряк
23436
48.943566
34.185650
Ветряк
....
这是我的密码:
一旦创建:
List<Location> gpxList = null;
File gpxFile = new File(Environment.getExternalStorageDirectory()
+ "/Shukach/shukach.gpx");
gpxList = decodeGPX(gpxFile);
List gpxList=null;
File gpxFile=新文件(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;
私有列表解码GPX(文件){
列表=新的ArrayList();
DocumentBuilderFactory DocumentBuilderFactory=DocumentBuilderFactory
.newInstance();
试一试{
DocumentBuilder DocumentBuilder=documentBuilderFactory
.newDocumentBuilder();
FileInputStream FileInputStream=新的FileInputStream(文件);
Document Document=documentBuilder.parse(fileInputStream);
Element elementRoot=document.getDocumentElement();
NodeList NodeList_wpt=elementRoot.getElementsByTagName(“wpt”);
for(int i=0;i
}
我无法理解这个问题,也无法在internet上找到解决方案…请提供帮助。您似乎希望
lat
和lon
是wpt
节点的属性,但在示例XML中,它们是子元素,因此您的代码可能不正确。您可以向我们显示.gpx文件的第136行吗?第136行:<ББББы---Бэнос-Айрес >