Ich versuche nächste XML-Dokument von SAX-Parser zu analysieren:SAX-Parser - Number
<?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>
Es ist in Zeichen:
if (thisElement.equals("numberOfDancers")) {
dance.setNumberOfDancers(new Integer((new String(ch, start, length))));
}
und das ist, was ich habe:
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);
Wo könnte das Problem sein?
Um eine bessere Antwort zu erhalten, zeigen Sie Ihren ContentHandler-Code. –