• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

xml/sax

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I was trying a sample XML Parser program using java with using jaxp1.1 and SAX2.0 software.I created a class "sampClass1" which simply counts the number of specific tags of a input XML file.It clean compiled(no errors/warnings).But when am executing the following is the error message i got
C:\>java sampClass1
Exception in thread "main" java.lang.NoClassDefFoundError: sampClass1
Following is the code.
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Locator;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
//import org.apache.xerces.parsers.SAXParser;
public class sampClass1 extends DefaultHandler
{
private int count = 0;
public static void main(String args[]) throws Exception
{
sampClass1 c1 = new sampClass1();
c1.bookCounter();
}
public void bookCounter() throws Exception
{
XMLReader xmlreader = null;
SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setValidating(false);
SAXParser spParser = spFactory.newSAXParser();
xmlreader = spParser.getXMLReader();
xmlreader.setContentHandler(this);
InputSource source = new InputSource("samp.xml");
xmlreader.parse(source);
//xmlreader.parse("file:///C:/samp.xml");
}
public void startElement(String name , Attributes atts) throws SAXException
{
if(name.equals("book"))
count++;
}
public void endDocument() throws SAXException
{
System.out.println("There are "+count+" books");
}
}
Please respond.
Thanks and Regards,
Muru.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check that the classpath is set properly. Also make sure that sampClass1.class has indeed been created. Hope this helps.
Hirdesh


[This message has been edited by hirdesh (edited September 12, 2001).]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hirdesh,
Please follow Javaranch's Login-name Convention.
Re-enroll as a member of this forum with First-name Last-name
as your Login ID. This is to ensure uniformity amongst the
members.
Have a nide time being around.
Regards,
Praveen
 
murugesan subramani
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hirdesh,
I did set the classpath properly and also there is the sampClass1.class present.But still it does not work.Can you please mail me of the .jar files to be set in the classpath and any other solution as i've tried everything possible.
Murugesan Subramani

Originally posted by hirdesh:
Please check that the classpath is set properly. Also make sure that sampClass1.class has indeed been created. Hope this helps.
Hirdesh


[This message has been edited by hirdesh (edited September 12, 2001).]


 
hirdesh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did it work?

Originally posted by murugesan subramani:
Hi Hirdesh,
I did set the classpath properly and also there is the sampClass1.class present.But still it does not work.Can you please mail me of the .jar files to be set in the classpath and any other solution as i've tried everything possible.
Murugesan Subramani


 
Maybe he went home and went to bed. And took this tiny ad with him:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic