Jump to content

Cannot launch JasperReport from eclipse plugi


Recommended Posts

By: Patrice Drolet - infodata

Cannot launch JasperReport from eclipse plugi

2003-06-13 04:19

Hi,

 

I have been trying to use JR for a plugin. I use Hibernate 2 and use a modified datasource:

 

public class HibernateQueryResultDataSource implements JRDataSource {

private String[] fields;

private Iterator iterator;

private Object currentValue;

 

public HibernateQueryResultDataSource(List list, String[] fields) {

this.fields = fields;

this.iterator = list.iterator();

}

 

/*

* @see dori.jasper.engine.JRDataSource#getFieldValue(dori.jasper.engine.JRField)

*/

public Object getFieldValue(JRField field) throws JRException {

Object value = null;

int index = getFieldIndex(field.getName());

if (index > -1) {

Object[] values = (Object[])currentValue;

value = values[index];

}

return value;

}

 

/*

* @see dori.jasper.engine.JRDataSource#next()

*/

public boolean next() throws JRException {

currentValue = iterator.hasNext() ? iterator.next() : null;

return (currentValue != null);

}

 

private int getFieldIndex(String field) {

int index = -1;

for (int i = 0; i < fields.length; i++) {

if (fields.equals(field)) {

index = i;

break;

}

}

return index;

}

 

}

///////////

here is the xml doc:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

 

<jasperReport name="Etablissements" pageWidth="595" pageHeight="842" columnWidth="540" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">

<field name="NOM_ETABL" class="java.lang.String">

</field>

<field name="NUM_ETABL" class="java.lang.String">

</field>

<field name="AGENCE" class="java.lang.String">

</field>

<field name="TYPELIEU" class="java.lang.String">

</field>

<field name="GROUPE" class="java.lang.String">

</field>

<field name="CATG" class="java.lang.String">

</field>

<field name="MODFS1" class="java.lang.String">

</field>

<field name="PKIDC" class="java.lang.String">

</field>

<title>

<band height="50">

<staticText>

<reportElement positionType="Float" x="0" y="0" width="842" height="50"/>

<textElement>

<font size="16" isBold="true"/>

</textElement>

<text><![CDATA[Etablissements]]></text>

</staticText>

</band>

</title>

<pageHeader>

<band>

</band>

</pageHeader>

<columnHeader>

<band height="20">

<staticText>

<reportElement positionType="Float" x="0" y="0" width="40" height="20"/>

<textElement>

<font isUnderline="true"/>

</textElement>

<text><![CDATA

Code:
]></text> 
</staticText>
<staticText>
<reportElement positionType="Float" x="50" y="0" width="200" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[Description]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement positionType="Float" x="0" y="0" width="40" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String">$F{NUM_ETABL}</textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="50" y="0" width="200" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String">$F{NOM_ETABL}</textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band>
</band>
</columnFooter>
<pageFooter>
<band height="40">
<line>
<reportElement x="0" y="10" width="515" height="0"/>
<graphicElement stretchType="NoStretch"/>
</line>
<textField>
<reportElement x="200" y="20" width="80" height="15"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String">
"Page " + String.valueOf($V{PAGE_NUMBER}) + " de"
</textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="280" y="20" width="75" height="15"/>
<textElement textAlignment="Left"/>
<textFieldExpression class="java.lang.String">
" " + String.valueOf($V{PAGE_NUMBER})
</textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band>
</band>
</summary>
</jasperReport>


And here is the code used to generate the report:
....
display.syncExec(new runIt());

class runIt implements Runnable {

/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
String printerChoice = getOpgChoix().getPreferenceStore().getString("printerChoice"«»);
String reportChoice = getReportList().getText();
System.out.println(printerChoice+" "+reportChoice);

List etabl = FmedxApp.getGetHib().getListEtabl();
// List forfOblig = FmedxApp.prevaylerData.forf_obligs;
//session.find("select cat.type, cat.birthdate, cat.name from cat in class eg.DomesticCat"«»);

Map parameters = new HashMap();
parameters.put("Title", "Liste des etablissements"«»);
ClassLoader cl=Thread.currentThread().getContextClassLoader();
InputStream reportStream = cl.getResourceAsStream("/eclipse/Etablissements.xml"«»);
System.out.println("apres le reportStream"«»);
try {
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
System.out.println("apres le jasperDesign"«»);
JasperReport jasperReport= JasperManager.compileReport(jasperDesign);
System.out.println("apres le jasperReport"«»);
String[] fields = new String[] { "pkidc", "agence", "catg","groupe","modfs1","nom_etabl","num_etabl","typelieu"};
HibernateQueryResultDataSource ds = new HibernateQueryResultDataSource(etabl, fields);
System.out.println("Apres le ds"«»);
JasperPrint jasperPrint= JasperManager.fillReport(jasperReport, parameters, ds);
System.out.println("apres les JasperPrint"«»);
JasperManager.printReportToPdfFile(jasperPrint, "etabl.pdf"«»);
} catch (JRException e) {
FmedxPlugin.logError(reportChoice, e);
}
}

}

Here is the error log that I get:
!SESSION juin 13, 2003 07:08:12.566 --------------------------------------------
java.version=1.4.1_01
java.vendor=Apple Computer, Inc.
BootLoader constants: OS=macosx, ARCH=ppc, WS=carbon, NL=fr_CA
Command-line arguments: -pdelaunch -dev bin -feature org.eclipse.platform -data /fmedx/runtime-workspace -os macosx -ws carbon -arch ppc -nl fr_CA -configuration file:/eclipse/workspace/.metadata/.plugins/org.eclipse.pde.core/_fmedx_runtime-workspace/platform.cfg -install file:/fmedx/
!ENTRY ca.infodata.fmedx 4 4 juin 13, 2003 07:08:12.568
!MESSAGE Noms des etablissements: NomEtabl
!STACK 0
java.lang.NullPointerException
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:524)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.apache.commons.digester.Digester.parse(Digester.java:1562)
at dori.jasper.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:373)
at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:357)
at dori.jasper.engine.JasperManager.loadXmlDesign(JasperManager.java:1026)
at ca.infodata.util.PrinterSelect$runIt.run(PrinterSelect.java:233)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:127)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:24)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:2539)
at ca.infodata.util.PrinterSelect.okPressed(PrinterSelect.java:268)
at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:256)
at ca.infodata.util.PrinterSelect.buttonPressed(PrinterSelect.java:211)
at org.eclipse.jface.dialogs.Dialog$1.widgetSelected(Dialog.java:423)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1016)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2082)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1795)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:583)
at org.eclipse.jface.window.Window.open(Window.java:563)
at ca.infodata.util.PrinterSelect.<init>(PrinterSelect.java:107)
at ca.infodata.fmedx.editor.ToolBarEditor$4.handleEvent(ToolBarEditor.java:104)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1016)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2082)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1795)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1399)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:1382)
at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858)
at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
at org.eclipse.core.launcher.Main.run(Main.java:747)
at org.eclipse.core.launcher.Main.main(Main.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at apple.launcher.LaunchRunner.run(LaunchRunner.java:88)
at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)

NESTED BY :
dori.jasper.engine.JRException: java.lang.NullPointerException
at dori.jasper.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:381)
at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:357)
at dori.jasper.engine.JasperManager.loadXmlDesign(JasperManager.java:1026)
at ca.infodata.util.PrinterSelect$runIt.run(PrinterSelect.java:233)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:127)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:24)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:2539)
at ca.infodata.util.PrinterSelect.okPressed(PrinterSelect.java:268)
at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:256)
at ca.infodata.util.PrinterSelect.buttonPressed(PrinterSelect.java:211)
at org.eclipse.jface.dialogs.Dialog$1.widgetSelected(Dialog.java:423)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1016)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2082)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1795)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:583)
at org.eclipse.jface.window.Window.open(Window.java:563)
at ca.infodata.util.PrinterSelect.<init>(PrinterSelect.java:107)
at ca.infodata.fmedx.editor.ToolBarEditor$4.handleEvent(ToolBarEditor.java:104)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1016)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2082)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1795)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1399)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:1382)
at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858)
at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
at org.eclipse.core.launcher.Main.run(Main.java:747)
at org.eclipse.core.launcher.Main.main(Main.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at apple.launcher.LaunchRunner.run(LaunchRunner.java:88)
at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)
Caused by: java.lang.NullPointerException
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:524)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.apache.commons.digester.Digester.parse(Digester.java:1562)
at dori.jasper.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:373)
... 41 more

///////////////////

Sorry this very long message, but I hope that somebody will help me out! Thanks for your answers.

Patrice Drolet




By: Teodor Danciu - teodord
RE: Cannot launch JasperReport from eclipse p
2003-06-13 05:08

Hi,

It looks like you are passing a null InputStream
to the JasperReports XML loader.
It think "/eclipse/Etablissements.xml" is not found
within the classpath when you run the code.

I hope this helps.
Teodor





By: Patrice Drolet - infodata
RE: Cannot launch JasperReport from eclipse p
2003-06-13 09:58
Thanks for this answer Teodor.

This is what I thought initially so I made copies of Etablissements.xml everywhere... I tried with /eclipse/ and without, with E and with e (not capital). To no avail...
:«»-(((

Where the file should be? There should be a kind of "check if file exists" before creating the report?

Could it be a conflict between parsers? I am completely lost here. I have spend many hours trying to make it work. If someone has any suggestion, I will listen! Thanks,

Patrice Drolet




By: Teodor Danciu - teodord
RE: Cannot launch JasperReport from eclipse p
2003-06-15 13:30

Hi,

I suggest you forget about JasperReports for a moment.
Just make your code read the first couple of bytes from the input stream
that you get with getResourceAsStream().
If you get this right and the file is found, then reintroduce JasperReports
into your code.

I know nothing about your plugin-in configuration and its classpath,
so its very hard to assume anything.

Try to make one step at a time.

This is clearly an Eclipse configuration issue and
not a JasperReports one.

I hope this helps.
Teodor
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...