CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2000
    Posts
    76

    Helloworld program on Java + XML! I am stuck even to compile with DefaultHandler

    Hi, I am newbies to use Java XML
    Can any body help, i have stuck for a long time.
    It should be simple for all who have ever use Java + XML.
    I am just compilling helloworld program on DefaultHandler
    but fail....

    Help pls...


    I download Xerces-J-bin.2.2.1 from http://xml.apache.org/dist/

    C:\xmltest>javac -classpath c:\xmltest\xercesImpl.jar;c:\xmltest\xercesSamples.j
    ar;c:\xmltest\xmlParserAPIs.jar CountSax.java

    C:\xmltest>java -classpath c:\xmltest\xercesImpl.jar;c:\xmltest\xercesSamples.ja
    r;c:\xmltest\xmlParserAPIs.jar CountSax
    Exception in thread "main" java.lang.NoClassDefFoundError: CountSax

    C:\xmltest>java CountSax
    Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/helpers/D
    efaultHandler
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)


    Below is the code:
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.SAXParser;


    public class CountSax extends DefaultHandler
    {
    public static void main(String argv[]) throws Exception
    {
    if (argv.length!=1)
    {
    System.err.println("u");
    System.exit(1);
    }

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser;
    try
    {
    saxParser = factory.newSAXParser();
    saxParser.parse(new File(argv[0]),new CountSax());

    }catch(ParserConfigurationException e)
    {
    System.out.println("he");
    }
    catch(SAXException e)
    {
    }
    catch(IOException e)
    {}
    }

    static private int eltCount = 0;

    public void startDocument()
    {

    }

    public void startElement(String name, String localName, String qName)
    {
    eltCount++;
    }

    public void endDocument()
    {
    System.out.println("Total number of elements"+eltCount);
    }
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    Put the current directory (where the CountSax.class file is) on the classpath:

    C:\xmltest>java -classpath .;c:\xmltest\xercesImpl.jar;c:\xmltest\xercesSamples.jar;c:\xmltest\xmlParserAPIs.jar CountSax

    Note the '.;' on the classpath. If you provide a classpath, the runtime uses nothing else.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Aug 2000
    Posts
    76

    Smile Super Thx

    What a bug!!

    I have stuck for a long time....
    (How come such a trick?)

    Thank you very much for your help.
    Otherwise, I may not be able to figure it out forever.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured