Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with SAXParserFactory!

 
Himal Chuli
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
 
Jayadev Pulaparty
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic