Forums Register Login

problem with SAXParserFactory!

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
i can't believe myself!! at times, i go blind..thanks for pointing it out.
himal
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 861 times.
Similar Threads
xml/sax
Why does the SAXParser give different result ?
Bind Variable?
How can I convert the xml to a string?
using abstract method and class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:56:25.