Well House Consultants Ltd.
spacer spacer
The Java Programming language - The language itself plus JSP, Servlets, Enterpise, Beans, etc


Classcast error - can anyone help?

Posted by mac24nz (mac24nz), 15 July 2005
I'm trying to improve an already existing program - as far as I know this used to work - so possibly the error is comming through incorrect jar files/environment - if so I don't know why....

basically the program should get a URL which has a jasper report and print this


//Merge Report Definition and Data
try
{
URL viewMetaFile = new URL(urlStr+"/StationReport.jasper");
                 
java.io.InputStream is = (viewMetaFile.openStream());
//openConnection().getInputStream();
                 
JRTableModelDataSource jtmbs = new JRTableModelDataSource(tModel);
System.out.println(viewMetaFile);      
System.out.println("viewMetaFile.openStream() is:"+is.getClass());
System.out.println("new JRTableModelDataSource(tModel) is Class:"+jtmbs.getClass());
System.out.println("parameters is class:"+parameters.getClass());
 JasperPrint jp = JasperFillManager.fillReport(is,
 parameters,
 jtmbs);
 //JasperViewer.viewReport(jp);
 JasperPrintManager.printReport(jp, true);
}
catch (Exception ex)......

The problem is the JasperPrint jp throws a class cast exception.  It is awaiting an InputStream, java.util.map and a JRTableModelDataSource.

Here is the error output:

http://localhost/bestterm/StationReport.jasper

viewMetaFile.openStream() is:class sun.net.www.protocol.http.HttpURLConnection$HttpInputStream
new JRTableModelDataSource(tModel) is class:class net.sf.jasperreports.engine.data.JRTableModelDataSource
parameters is class:class java.util.HashMap
java.lang.ClassCastException
     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:33
     at de.mc.etnbestterm.gui.OEListPanel.printStationsListe(OEListPanel.java:336)
     at de.mc.etnbestterm.gui.BestellPanel.printStationsListe(BestellPanel.java:343)
     at de.mc.etnbestterm.gui.BestellMainPanel.printStationsListe(BestellMainPanel.java:36
     at de.mc.etnbestterm.gui.MainFrame.printStationsListe(MainFrame.java:369)
     at de.mc.etnbestterm.gui.MainMenuBar.m_fileItemPrintStationsListe_actionPerformed(MainMenuBar.java:606)
     at de.mc.etnbestterm.gui.MainMenuBar.access$4(MainMenuBar.java:604)
     at de.mc.etnbestterm.gui.MainMenuBar$5.actionPerformed(MainMenuBar.java:142)
     at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
     at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
     at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
     at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:25
     at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
     at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
     at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
     at java.awt.Component.processMouseEvent(Component.java:5100)
     at java.awt.Component.processEvent(Component.java:4897)
     at java.awt.Container.processEvent(Container.java:1569)
     at java.awt.Component.dispatchEventImpl(Component.java:3615)
     at java.awt.Container.dispatchEventImpl(Container.java:1627)
     at java.awt.Component.dispatchEvent(Component.java:3477)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:319
     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:312
     at java.awt.Container.dispatchEventImpl(Container.java:1613)
     at java.awt.Window.dispatchEventImpl(Window.java:1606)
     at java.awt.Component.dispatchEvent(Component.java:3477)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

what I find key here is that the class of viewMetaFile.openStream() is:class sun.net.www.protocol.http.HttpURLConnection$HttpInputStream
this should be InputStream - so this is probably causing the classcastexception

URL viewMetaFile = new URL(urlStr+"/StationReport.jasper");
                 
java.io.InputStream is = (viewMetaFile.openStream());

why is this not producing the specified InputStream - or ok - this is an abstract class - so maybe it can't be this.  But I can't even find any doc on the private class that is being produced.  It all seems a bit odd.  

I've also read thoughts that the MIME Type of the jasper file could be important - what is the MIME Type of a jasper file?


Does anyone have any ideas? I'd be really grateful.

Thanks

Martin





This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.
spacer

You can Add a comment or ranking to this page

WELL HOUSE CONSULTANTS LTD • 404, The Spa • Melksham, Wiltshire SN12 6QL • United Kingdom
PHONE: 01144 1225 708225 • FACSIMILE 01144 1225 793803 • EMAIL: info@wellho.net
You are currently on our United States site. Change your country.
Privacy and Copyright StatementTerms and Conditions
Updated Saturday, April 27th 2024 • © Well House Consultants, 2024

This is page http://www.wellho.net/forum/The-Java-Programming-language/Classcast-error-can-anyone-help.html