NoSuchMethodError

Albert Pi <[email protected]> Wed, 20 Nov 2002 14:34:28 -0500
Newsgroups gmane.comp.java.sun.xml.general
Message-ID <[email protected]>
All:
     I wrote very simple java is using parser read xml and output to "name,value" format,
     but I got   NoSuchMethodError this error. I added "w3cdom1.jar in my classpath". 
     Is that right jar file ? Please advise, thanks.

  F:\SRC\JAVASRC\XML>C:\jdk1.3.1_01\jre\bin\java DOMBuilder test.xml
java.lang.NoSuchMethodError
        at org.apache.crimson.tree.XmlDocumentBuilder.startDTD(XmlDocumentBuilde
r.java:633)
        at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1119)

        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)

        at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl
.java:185)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:191)
        at DOMBuilder.main(DOMBuilder.java:27)

F:\SRC\JAVASRC\XML>C:\jdk1.3.1_01\jre\bin\java DOMBuilder test.xml
java.lang.NoSuchMethodError
        at org.apache.crimson.tree.XmlDocumentBuilder.startDTD(XmlDocumentBuilde
r.java:633)
        at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1119)

        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)

        at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl
.java:185)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:191)
        at DOMBuilder.main(DOMBuilder.java:27)


The folllowings are my java code:
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.*;
import java.io.*;


public class DOMBuilder
{

    public static void main(String args[])
    {
        if(args.length <1)
        {
                        System.out.println("Usage java ***.xml ");
                        System.exit(1);
                }
                try {
                         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                         factory.setValidating(true);
                         DocumentBuilder builder        = factory.newDocumentBuilder();
                         Document doc                   = builder.parse(new File(args[0]));
                         Element root                   = doc.getDocumentElement();
                         root.normalize();
                         OutputNodes(root,System.out);
           } catch(Throwable t)
              {
                          t.printStackTrace();
               }
        }

  private static void OutputNodes(Node n,OutputStream out) throws IOException
  {
          if(n == null)
            return;

       out.write(("Node name:" + n.getNodeName() + ": value:" + n.getNodeValue()
                  + "\n").getBytes());
       NodeList list = n.getChildNodes();
         if(list == null)
            return;

         else
          {
                          int Length = list.getLength();
                          for(int i =0;i<Length;i++)
                            {
                                        OutputNodes(list.item(i),out);
                                }
                  }

  }

}

Albert Pi
Corp IS System Delivery
516-803-3762

-----------------------------------------------------
xml-interest: A list for discussing XML technologies in the Java Platform.
To post, mailto:[email protected]
Archives at: http://archives.java.sun.com/xml-interest.html
To unsubscribe, mailto:[email protected] the following message;
signoff xml-interest.