各位好,项目中遇到个问题,想请教下大家。
我在读取xml的时候用到了selectSingleNode方法,在本地的时候没有问题,但在linux主机下部署的时候报错
报错信息:
2013-02-04 14:57:17.962|WARNING|stream.err|_ThreadID=20;_ThreadName=httpWorkerThread-14826-3;_RequestID=654a1ff8-3917-41fc-9381-13662c433794;|java.lang.NullPointerException
at org.jaxen.util.DescendantAxisIterator.hasNext(DescendantAxisIterator.java:94)
at org.jaxen.expr.DefaultStep.evaluate(DefaultStep.java:166)
at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:154)
at org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(DefaultAbsoluteLocationPath.java:121)
at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:112)
at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:688)
at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:227)
at org.jaxen.BaseXPath.selectSingleNode(BaseXPath.java:248)
at org.dom4j.xpath.DefaultXPath.selectSingleNode(DefaultXPath.java:156)
at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:188)
at com.ailk.sgmonitor.monitor.service.impl.OperateConfigXmlServerSVImpl.getSomeMax(OperateConfigXmlServerSVImpl.java:1497)
at com.ailk.sgmonitor.monitor.service.impl.OperateConfigXmlServerSVImpl.getServiceConfigMsg(OperateConfigXmlServerSVImpl.java:1054)
源代码
private int getSomeMax(Element processesElement,String maxName){
int max=1;
if(processesElement!=null){
Element sdcElement=(Element)processesElement.selectSingleNode("process[procname='"+maxName+"']");
if(sdcElement!=null){
String maxText=sdcElement.elementText("max");
try {
max=Integer.parseInt(maxText);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new SystemException("配置文件有误,请检查server.xml!");
}
}
}
return max;
}
错误出在Element sdcElement=(Element)processesElement.selectSingleNode("process[procname='"+maxName+"']");
processesElement是Element processElement=localRoot.element(Constants.SERVICE_XML.PROCESSES);这么获取的
xml大概格式
<processes>
<process>
<procname>metarep</procname>
<prcid>90</prcid>
<priority>9</priority>
<pgname>GRP1</pgname>
<args>-A -- --conf=etc/metarep.xml</args>
</process>
<process>
<procname>kmngr</procname>
<prcid>110</prcid>
<priority>11</priority>
<pgname>GRP1</pgname>
<args>-A</args>
</process>
</processes>
请教各位我那个那个查询方法,哪里有问题谢谢!
xml NullPointerException
------解决方案--------------------
就是类有没有实现Serializable这个接口?xpath要写完整路径。