我試圖通過SAX解析器來解析下一個XML文檔:SAX解析器 - NumberFormatException的
<?xml version="1.0" encoding="UTF-8" ?>
<dance title="foxtrot" id="1">
<type>ballroom</type>
<scene>assembly hall</scene>
<numberOfDancers>10</numberOfDancers>
<music>phonogram</music>
<dancers>
<dancer>Ivanov Ivan</dancer>
<dancer>Petrova Ludmila</dancer>
</dancers>
<number>22</number>
</dance>
它在人物:
if (thisElement.equals("numberOfDancers")) {
dance.setNumberOfDancers(new Integer((new String(ch, start, length))));
}
,這就是我得到:
java.lang.NumberFormatException: For input string: "
"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at parsers.SAXParser.characters(SAXParser.java:58)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.characters(AbstractSAXParser.java:546)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:328)
at Main.main(Main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Integer.java:569 is next:
} else if (firstChar != '+')
throw NumberFormatException.forInputString(s);
問題在哪裏?
要獲得更好的答案,請顯示您的ContentHandler代碼。 –