Actually the Variables view in Eclipse right before the line
executes shows:
saxParser=SaxParserImpl
(id=50)
namespaceAware=false
parser=null
validating=false
....
The "parser=null" designation in the Eclipse
variables window does not seem right but I have looked at the documentation
several times and it look like I should have a valid SAXParser
instance.
According to the Javadoc, there is description of the
appropriate parse method for a SAXParser:
parse
public void parse(File f, DefaultHandler dh) throws SAXException, IOException
- Parse the content of the file specified as XML using the specified
DefaultHandler.- Parameters:
f- The file containing the XML to parsedh- The SAX DefaultHandler to use.- Throws:
IOException- If any IO errors occur.IllegalArgumentException- If the File object is null.SAXException- If the underlying parser throws a SAXException while parsing.- See Also:
DocumentHandler
The stack trace is as follows:
java.lang.NullPointerException
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:281)
at Tree.rulesTree.main(rulesTree.java:103)
Ray
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Richard O. Hammer
Sent: Wednesday, April 06, 2005 7:10 PM
To: Research Triangle Java User's Group mailing list.
Subject: Re: [Juglist] SAX Parse Exception
I wonder if your variable saxParser is null.
Raymond Hooker (rhooker) wrote:
> Pardon the basic question but I cannot see what the problem is. I was
> going through the SAX tutorials using Eclipse 3.0.2 and Java SDK
> 1.4.2_07. Anyhow the following code gets throws
> java.lang.NullPointerException:
>
>
> String rulesFile =
> fileDialog.getDirectory()+fileDialog.getFile();
> // Use an instance of ourselves as the SAX event handler
> DefaultHandler handler = new Echo();
>
> // Use the default (non-validating) parser
> SAXParserFactory factory =
> SAXParserFactory.newInstance();
> try {
> // Set up output stream
> out = new OutputStreamWriter(System.out, "UTF8");
>
> // Parse the input
> File Filerules = new File(rulesFile);
> SAXParser saxParser = factory.newSAXParser();
> saxParser.parse( Filerules, handler ); <----Exception occurs
> here
>
> } catch (Throwable t) {
> t.printStackTrace();
> }
>
> I verified that by a breakpoint that the time of exception Filerules
> was File object that is not null, and handler is a Echo instance.
> Echo is class that extends DefaultHandler. Echo has a number of
> methods to handle events like startDocument and startElement.
> According to the JavaDoc, I don't believe that the parse method is
> supposed to throw a nullPointerException. BTW the actual stack trace is:
>
> java.lang.NullPointerException
> at
> org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
> at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
> at
> org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:281)
> at Tree.rulesTree.main(rulesTree.java:103)
>
> I have tried various file contents.
>
> Ray
>
> _______________________________________________
> Juglist mailing list
> [email protected]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>
_______________________________________________
Juglist mailing list
[email protected]
http://trijug.org/mailman/listinfo/juglist_trijug.org
_______________________________________________ Juglist mailing list [email protected] http://trijug.org/mailman/listinfo/juglist_trijug.org
