You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Per Eckerdal <ed...@shell.linux.se> on 2004/03/06 09:07:27 UTC
Why this exception?
Hello,
When I run this code,
System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
// Instantiate a TransformerFactory.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Determine whether the TransformerFactory supports The use uf
SAXSource
// and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE) &&
tFactory.getFeature(SAXResult.FEATURE))
{
// Cast the TransformerFactory to SAXTransformerFactory.
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)
tFactory);
// Create a TransformerHandler for each stylesheet.
TransformerHandler tHandler1 =
saxTFactory.newTransformerHandler(new
StreamSource("c:\\programmering\\xml\\test\\hello.xsl"));
//TransformerHandler tHandler2 =
saxTFactory.newTransformerHandler(new StreamSource("foo2.xsl"));
//TransformerHandler tHandler3 =
saxTFactory.newTransformerHandler(new StreamSource("foo3.xsl"));
// Create an XMLReader.
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(tHandler1);
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
tHandler1);
//tHandler1.setResult(new SAXResult(tHandler2));
//tHandler2.setResult(new SAXResult(tHandler3));
// transformer3 outputs SAX events to the serializer.
Serializer serializer =
SerializerFactory.getSerializer(OutputPropertiesFactory.getDefaultMethodProperties("xml"));
serializer.setOutputStream(System.out);
tHandler1.setResult(new
SAXResult(serializer.asContentHandler())); // This line is changed from
tHandler3 to tHandler1
// Parse the XML input document. The input ContentHandler
and output ContentHandler
// work in separate threads to optimize performance.
reader.parse("c:\\programmering\\xml\\test\\hello.xml");
}
I get the exception
java.lang.RuntimeException: java.lang.NullPointerException
at org.apache.xalan.transformer.TransformerImpl.run(Unknown Source)
at
org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(Unknown
Source)
at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown
Source)
at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at eoner.TestClass.<init>(TestClass.java:97)
at eoner.TestClass.main(TestClass.java:182)
I have no idea of what this is. For the ones who want to know this code
is almost directly copied from the Pipe example, except the lines i've
commented out and I've the line where tHandler3's result is set to the
serializer so tHandler1's result is set to that because when I test I'm
trying to keep things simple, so I limited the test to just one xsl file.
I'm not setting any system properties except the one I set in the first
line of the code.
There is no code before that in the constructor of TestClass, and the
main method do only call the constructor and catch exceptions.
/Pelle