我的 XML 和 Bean 与属性“CostCenter”完美匹配,但仍然存在这个问题。请帮助解决这个问题。
例外 :
Sep 13, 2013 4:25:23 PM org.apache.commons.digester3.Digester endElement
SEVERE: End event threw exception
java.lang.NoSuchMethodException: Bean has no property named CostCenter
at org.apache.commons.digester3.BeanPropertySetterRule.end(BeanPropertySetterRule.java:206)
at org.apache.commons.digester3.Digester.endElement(Digester.java:1097)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.commons.digester3.Digester.parse(Digester.java:1588)
at org.apache.commons.digester3.Digester.parse(Digester.java:1557)
at ecnet.yes.po.digester.DigestPO.digest(DigestPO.java:80)
at ecnet.yes.po.digester.DigestPO.main(DigestPO.java:16)
Sep 13, 2013 4:25:23 PM org.apache.commons.digester3.Digester parse
SEVERE: An error occurred while parsing XML from 'file:/D:/workspace/Digester/src/ecnet/yes/po/digester/YES_PO.xml', see nested exceptions
DigestPO.java
Digester digester = new Digester();
//Push the current object onto the stack
digester.push(this);
digester.addSetProperties("ECnetPO");
//Creates a new instance of the YESBarePO class
digester.addObjectCreate("ECnetPO/Header", YESBarePO.class );
//Uses setName method of the YESBarePO instance
//Uses tag name as the property name
digester.addBeanPropertySetter("ECnetPO/Header/PONumber","PONumber");
digester.addBeanPropertySetter("ECnetPO/Header/CostCenter","CostCenter");
xml:
<ECnetPO>
<Header>
<PONumber>PONUMB0116</PONumber>
<CostCenter>Cost Center 20</CostCenter>
</Header>
<Header>
<PONumber>PONUMB0116</PONumber>
<CostCenter>Cost Center 20</CostCenter>
</Header>
</ECnetPO>
YESBarePO.java
private String PONumber;
private String CostCenter;
public String getPONumber()
{
return PONumber;
}
public void setPONumber(String pONumber)
{
PONumber = pONumber;
}
public String getCostCenter()
{
return CostCenter;
}
public void setCostCenter(String costCenter)
{
CostCenter = costCenter;
}