ClassCastException:
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:
Object x = new Integer(0); System.out.println((String)x);
Looking at your code, I think you'd better make your fos object be of type 'FileOutputStream' instead of just 'OutputStream', or add an explicit type cast before the new instruction...
More in general, the above exception can also occur when overloading classes in one jar with ones in another jar. They carry the same name and package, but are still in different namespaces actually...
Hope this helps, Geert
Arijit Banerjee wrote:
*Hi there,*
*I've a program which should convert an XML file to excel file format.I exported the XML file from MS-Excel XP.I'm getting a ClassCastException when I'm trying to convert the exported xml file to xls.I'm using cocoon-2.0.4 with jdom 1.0. What could be the problem?*
*The original xls and the exported xml file is attached.Both the xml and xls are opening fine with MS Excel XP*
*NOTE: The attached XML is exported from MS EXCELL XP and not generated by the code give below.*
java.lang.ClassCastException: org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyles
at org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyle.initialize(EPStyle.java:160)
at org.apache.cocoon.serialization.ElementProcessorSerializer.startElement(ElementProcessorSerializer.java:508)
at org.jdom.output.SAXOutputter.startElement(SAXOutputter.java:1025)
at org.jdom.output.SAXOutputter.element(SAXOutputter.java:894)
at org.jdom.output.SAXOutputter.elementContent(SAXOutputter.java:1093)
at org.jdom.output.SAXOutputter.elementContent(SAXOutputter.java:1067)
at org.jdom.output.SAXOutputter.element(SAXOutputter.java:897)
at org.jdom.output.SAXOutputter.elementContent(SAXOutputter.java:1093)
at org.jdom.output.SAXOutputter.elementContent(SAXOutputter.java:1067)
at org.jdom.output.SAXOutputter.element(SAXOutputter.java:897)
at org.jdom.output.SAXOutputter.output(SAXOutputter.java:621)
at XMLExcel.main(XMLExcel.java:43)
*public* *class* XMLExcel {
*public* *static* *void* main(String[] args) { File infile = *new* File( "C:/ari.xml" ); File outfile = *new* File( "C:/ari.xls" );
*try* { outfile.createNewFile(); OutputStream fos = *new* FileOutputStream( outfile ); SAXBuilder builder = *new* SAXBuilder(); Document doc = builder.build( infile );
HSSFSerializer hssf = *new* HSSFSerializer(); hssf.initialize(); hssf.setOutputStream( fos );
SAXOutputter saxOutput = *new* SAXOutputter( hssf ); saxOutput.output( doc );
System.out.println( "Done" ); } *catch* ( Exception e ) { e.printStackTrace(); }
} }
Thanks!! Regards, Arijit
------------------------------------------------------------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- [EMAIL PROTECTED] IT-consultant at Daidalos BV, Zoetermeer (NL)
http://www.daidalos.nl/ tel:+31-(0)79-3316961 fax:+31-(0)79-3316464
GPG: 1024D/12DEBB50
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
