• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

problem with SAXParserFactory!

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
while going thru IBM SAX tutorial, i ran into a problem. i have the following class:
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;
public class SurveyReader extends DefaultHandler{
public SurveyReader(){
System.out.println("Object Created.");
}
public void showEvent(String name){
System.out.println("Hello ," + name + "!");
}
public static void main(String[] args){
XMLReader xmlReader = null;

try{
SAXParserFactory spfactory = new SAXParserFactory.newInstance();
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
}catch(Exception e){
System.err.println(e);
System.exit(1);
}
}
}
i have dowloaded JAXP from Sun site and put it into path too. when i compile this class, the follwing is reported:
SurveyReader.java:19: cannot resolve symbol
sysmbol : class newInstance
location: class javax.xml.parsers.SAXParserFactory
SAXParserFactory spfactory = new SAXParserFactory.newInstance();
could anyone point out what wrong with it? appreciate your help. thanks.
himal
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
newInstance is a static method on the SAXParserFactory class; please remove the "new" and call it as shown below -
SAXParserFactory spfactory =
SAXParserFactory.newInstance();
This should do the trick
 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can't believe myself!! at times, i go blind..thanks for pointing it out.
himal
 
You showed up just in time for the waffles! And this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic