[jdom-interest] NoSuchElementException in jdom-b5 ?

Marek mdolgos at north-pacific.com
Wed Oct 11 11:22:30 PDT 2000


When I execute this code with nodeName equal to FORM_CODE and nodeValue
equal to newhire.

 public void setNodeValue (String nodeName, String nodeValue) {
      Element element = this.document.getRootElement ().getChild
(nodeName);
      if (element != null) {
         element.setText (nodeValue);
      }
}

I get this exception: (I am using jdom-b5) 


org.jdom.NoSuchElementException: The element FORM_CODE does not exist
within the specified element.
        at org.jdom.Element.getChild(Element.java:558)
        at JdomHelper.setNodeValue(JdomHelper.java:83)
        at FormProcessor.doPost(FormProcessor.java:111)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:597)
        at
org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java:257)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
        at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:156)
        at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
        at java.lang.Thread.run(Thread.java:484)


I know that this happens when the setNodeValue function is called with a
node name that does not exist in the document (namely FORM_CODE). What I
don't understand is why its throwing this exception. I thought
getChild() should return a null value if it can't find the node and the
if statement should catch that. Is NoSuchElementException even in
jdom-b5 ? I just upgraded from jdom-b3 to jdom-b5. Before when I was
using jdom-b3 I had a try catch where I would catch the
NoSuchElementException and ignore it (ya I know that its bad form
but...). Any help would be appreciated.

Marek
mdolgos at north-pacific.com



More information about the jdom-interest mailing list