Jump to content
Changes to the Jaspersoft community edition download ×

Dynamicdesign Report - Error Compiling Report


2004 IR Help

Recommended Posts

By: chin05 - chin05

Dynamicdesign Report - Error Compiling Report

2005-02-18 07:11

I get the error message.

"net.sf.jasperreports.engine.JRException: Error compiling report java source file : C:ReferenceMyreport.java"

 

Here is the scenario...please let me know its going wrong...Thanks

 

I am trying to design report dynamically. i.e adding used selected columns to the report. I am using the example of "noXMLDesing" example. I have

 

poi-bin-2.5.1-final-20040804.jar

commons-digester-1.6

commons-beanutils-1.7.0

commons-logging-1.0.4

commons-collections-3.1

jasperreports-0.6.4

itext.jar

 

in my Java Build path ->Libraries

 

Here is my Code in the .java

 

public void runReport(Connection con)

 

{

try{

Map parameters = new HashMap();

String filename = null;

filename = "raga";

 

parameters.put("ReportTitle", "Address Report");

parameters.put("OrderByClause", "ORDER BY title");

 

JasperDesign mydesign = new JasperDesign();

mydesign = myJasperDesign();

JasperReport jasperReport = JasperCompileManager.compileReport(mydesign);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,con);

JasperViewer.viewReport(jasperPrint,false);

 

}

catch(JRException e){

System.out.println(e.toString());

}

 

}

 

private static JasperDesign myJasperDesign() throws JRException

{

//JasperDesign

JasperDesign jasperDesign = new JasperDesign();

jasperDesign.setName("Myreport");

jasperDesign.setPageWidth(595);

jasperDesign.setPageHeight(842);

jasperDesign.setColumnWidth(515);

jasperDesign.setColumnSpacing(0);

jasperDesign.setLeftMargin(40);

jasperDesign.setRightMargin(40);

jasperDesign.setTopMargin(50);

jasperDesign.setBottomMargin(50);

 

//Fonts

JRDesignReportFont normalFont = new JRDesignReportFont();

normalFont.setName("Arial_Normal");

normalFont.setDefault(true);

normalFont.setFontName("Arial");

normalFont.setSize(12);

normalFont.setPdfFontName("Helvetica");

normalFont.setPdfEncoding("Cp1252");

normalFont.setPdfEmbedded(false);

jasperDesign.addFont(normalFont);

 

JRDesignReportFont boldFont = new JRDesignReportFont();

boldFont.setName("Arial_Bold");

boldFont.setDefault(false);

boldFont.setFontName("Arial");

boldFont.setSize(12);

boldFont.setBold(true);

boldFont.setPdfFontName("Helvetica-Bold");

boldFont.setPdfEncoding("Cp1252");

boldFont.setPdfEmbedded(false);

jasperDesign.addFont(boldFont);

 

JRDesignReportFont italicFont = new JRDesignReportFont();

italicFont.setName("Arial_Italic");

italicFont.setDefault(false);

italicFont.setFontName("Arial");

italicFont.setSize(12);

italicFont.setItalic(true);

italicFont.setPdfFontName("Helvetica-Oblique");

italicFont.setPdfEncoding("Cp1252");

italicFont.setPdfEmbedded(false);

jasperDesign.addFont(italicFont);

 

//Parameters

JRDesignParameter parameter = new JRDesignParameter();

parameter.setName("ReportTitle");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

parameter = new JRDesignParameter();

parameter.setName("OrderByClause");

parameter.setValueClass(java.lang.String.class);

jasperDesign.addParameter(parameter);

 

//Query

JRDesignQuery query = new JRDesignQuery();

query.setText("SELECT * FROM reference_det $P!{OrderByClause}");

jasperDesign.setQuery(query);

 

//Fields

JRDesignField field = new JRDesignField();

field.setName("REF_DET_TITLE");

field.setValueClass(java.lang.Integer.class);

jasperDesign.addField(field);

 

 

field = new JRDesignField();

field.setName("REF_DET_FIRST_NAME");

field.setValueClass(java.lang.Integer.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("REF_DET_MIDDLE_NAME");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("REF_DET_LAST_NAME");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("REF_DET_ADDRESS");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("REF_DET_CITY");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

//Variables

JRDesignVariable variable = new JRDesignVariable();

variable.setName("CityNumber");

variable.setValueClass(java.lang.Integer.class);

variable.setResetType(JRVariable.RESET_TYPE_GROUP);

JRDesignGroup group = new JRDesignGroup();

group.setName("CityGroup");

variable.setResetGroup(group);

variable.setCalculation(JRVariable.CALCULATION_SYSTEM);

JRDesignExpression expression = new JRDesignExpression();

expression.setValueClass(java.lang.Integer.class);

expression.setText("($V{CityNumber} != null)?(new Integer($V{CityNumber}.intValue() + 1)):(new Integer(1))");

variable.setInitialValueExpression(expression);

jasperDesign.addVariable(variable);

 

variable = new JRDesignVariable();

variable.setName("AllCities");

variable.setValueClass(java.lang.String.class);

variable.setResetType(JRVariable.RESET_TYPE_REPORT);

variable.setCalculation(JRVariable.CALCULATION_SYSTEM);

jasperDesign.addVariable(variable);

 

//Groups

group.setMinHeightToStartNewPage(60);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{REF_DET_CITY}");

group.setExpression(expression);

 

JRDesignBand band = new JRDesignBand();

band.setHeight(20);

JRDesignRectangle rectangle = new JRDesignRectangle();

rectangle.setX(0);

rectangle.setY(4);

rectangle.setWidth(515);

rectangle.setHeight(15);

rectangle.setForecolor(new Color(0xC0, 0xC0, 0xC0));

rectangle.setBackcolor(new Color(0xC0, 0xC0, 0xC0));

band.addElement(rectangle);

JRDesignTextField textField = new JRDesignTextField();

textField.setX(0);

textField.setY(4);

textField.setWidth(515);

textField.setHeight(15);

textField.setBackcolor(new Color(0xC0, 0xC0, 0xC0));

textField.setMode(JRElement.MODE_OPAQUE);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

textField.setFont(boldFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("" " + String.valueOf($V{CityNumber}) + ". " + String.valueOf($F{REF_DET_CITY})");

textField.setExpression(expression);

band.addElement(textField);

JRDesignLine line = new JRDesignLine();

line.setX(0);

line.setY(19);

line.setWidth(515);

line.setHeight(0);

band.addElement(line);

group.setGroupHeader(band);

 

band = new JRDesignBand();

band.setHeight(20);

line = new JRDesignLine();

line.setX(0);

line.setY(-1);

line.setWidth(515);

line.setHeight(0);

band.addElement(line);

JRDesignStaticText staticText = new JRDesignStaticText();

staticText.setX(400);

staticText.setY(0);

staticText.setWidth(60);

staticText.setHeight(15);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

staticText.setFont(boldFont);

staticText.setText("Count : ");

band.addElement(staticText);

textField = new JRDesignTextField();

textField.setX(460);

textField.setY(0);

textField.setWidth(30);

textField.setHeight(15);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

textField.setFont(boldFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.Integer.class);

expression.setText("$V{CityGroup_COUNT}");

textField.setExpression(expression);

band.addElement(textField);

group.setGroupFooter(band);

 

jasperDesign.addGroup(group);

 

//Title

band = new JRDesignBand();

band.setHeight(50);

line = new JRDesignLine();

line.setX(0);

line.setY(0);

line.setWidth(515);

line.setHeight(0);

band.addElement(line);

textField = new JRDesignTextField();

textField.setBlankWhenNull(true);

textField.setX(0);

textField.setY(10);

textField.setWidth(515);

textField.setHeight(30);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);

JRDesignReportFont bigFont = new JRDesignReportFont();

bigFont.setName("Arial_Normal");

bigFont.setDefault(true);

bigFont.setFontName("Arial");

bigFont.setSize(22);

bigFont.setPdfFontName("Helvetica");

bigFont.setPdfEncoding("Cp1252");

bigFont.setPdfEmbedded(false);

textField.setFont(bigFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$P{ReportTitle}");

textField.setExpression(expression);

band.addElement(textField);

jasperDesign.setTitle(band);

 

//Page header

band = new JRDesignBand();

band.setHeight(20);

rectangle = new JRDesignRectangle();

rectangle.setX(0);

rectangle.setY(5);

rectangle.setWidth(515);

rectangle.setHeight(15);

rectangle.setForecolor(new Color(0x33, 0x33, 0x33));

rectangle.setBackcolor(new Color(0x33, 0x33, 0x33));

band.addElement(rectangle);

staticText = new JRDesignStaticText();

staticText.setX(0);

staticText.setY(5);

staticText.setWidth(55);

staticText.setHeight(15);

staticText.setForecolor(Color.white);

staticText.setBackcolor(new Color(0x33, 0x33, 0x33));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);

staticText.setFont(boldFont);

staticText.setText("REF_DET_TITLE");

band.addElement(staticText);

staticText = new JRDesignStaticText();

staticText.setX(55);

staticText.setY(5);

staticText.setWidth(205);

staticText.setHeight(15);

staticText.setForecolor(Color.white);

staticText.setBackcolor(new Color(0x33, 0x33, 0x33));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setFont(boldFont);

staticText.setText("REF_DET_FIRST_NAME");

band.addElement(staticText);

staticText = new JRDesignStaticText();

staticText.setX(260);

staticText.setY(5);

staticText.setWidth(255);

staticText.setHeight(15);

staticText.setForecolor(Color.white);

staticText.setBackcolor(new Color(0x33, 0x33, 0x33));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setFont(boldFont);

staticText.setText("REF_DET_ADDRESS");

band.addElement(staticText);

jasperDesign.setPageHeader(band);

 

//Column header

band = new JRDesignBand();

jasperDesign.setColumnHeader(band);

 

//Detail

band = new JRDesignBand();

band.setHeight(20);

textField = new JRDesignTextField();

textField.setX(0);

textField.setY(4);

textField.setWidth(50);

textField.setHeight(15);

textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.Integer.class);

expression.setText("$F{REF_DET_TITLE}");

textField.setExpression(expression);

band.addElement(textField);

textField = new JRDesignTextField();

textField.setStretchWithOverflow(true);

textField.setX(55);

textField.setY(4);

textField.setWidth(200);

textField.setHeight(15);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{REF_DET_FIRST_NAME} + " " + $F{REF_DET_LAST_NAME}");

textField.setExpression(expression);

band.addElement(textField);

textField = new JRDesignTextField();

textField.setStretchWithOverflow(true);

textField.setX(260);

textField.setY(4);

textField.setWidth(255);

textField.setHeight(15);

textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{REF_DET_ADDRESS}");

textField.setExpression(expression);

band.addElement(textField);

line = new JRDesignLine();

line.setX(0);

line.setY(19);

line.setWidth(515);

line.setHeight(0);

line.setForecolor(new Color(0x80, 0x80, 0x80));

line.setPositionType(JRElement.POSITION_TYPE_FLOAT);

band.addElement(line);

jasperDesign.setDetail(band);

 

//Column footer

band = new JRDesignBand();

jasperDesign.setColumnFooter(band);

 

//Page footer

band = new JRDesignBand();

jasperDesign.setPageFooter(band);

 

//Summary

band = new JRDesignBand();

jasperDesign.setSummary(band);

 

 

 

return jasperDesign;

}

 

 

 

 

 

 

By: chin05 - chin05

RE: Dynamicdesign Report - Error Compiling Report

2005-02-18 13:20

I am making little progress..The report is getting compiled. The error is now in filling the report.

Anyone help please...I connect to Access database thru JDBC-ODBC. Connection is established fine and is tested for retrieving data to display on Jtables.

 

 

Exception occurred during event dispatching:

java.lang.NullPointerException

at net.sf.jasperreports.engine.fill.JRFillTextElement$1.chop(JRFillTextElement.java:515)

at net.sf.jasperreports.engine.fill.JRFillStaticText.fill(JRFillStaticText.java:241)

at net.sf.jasperreports.engine.fill.JRFillBand.fillElements(JRFillBand.java:756)

at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:487)

at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:447)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageBand(JRVerticalFiller.java:1269)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:396)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:248)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:162)

at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:691)

at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:519)

at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:120)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:291)

at ReportQuery.runReport(ReportQuery.java:181)

at ReportQuery.fillgrid(ReportQuery.java:144)

at ReportQuery$1.actionPerformed(ReportQuery.java:83)

at javax.swing.JComboBox.fireActionEvent(JComboBox.java:882)

at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:906)

at javax.swing.JComboBox.contentsChanged(JComboBox.java:962)

at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:93)

at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:100)

at javax.swing.JComboBox.setSelectedItem(JComboBox.java:426)

at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:467)

at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:634)

at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:245)

at java.awt.Component.processMouseEvent(Component.java:3799)

at java.awt.Component.processEvent(Component.java:3628)

at java.awt.Container.processEvent(Container.java:1195)

at java.awt.Component.dispatchEventImpl(Component.java:2678)

at java.awt.Container.dispatchEventImpl(Container.java:1244)

at java.awt.Component.dispatchEvent(Component.java:2581)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2487)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2252)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2161)

at java.awt.Container.dispatchEventImpl(Container.java:1231)

at java.awt.Window.dispatchEventImpl(Window.java:964)

at java.awt.Component.dispatchEvent(Component.java:2581)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:434)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:172)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:131)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:126)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:118)

 

 

JasperDesign mydesign = new JasperDesign();

mydesign = myJasperDesign();

System.out.println("AfterGetDesign");

JasperReport jasperReport = JasperCompileManager.compileReport(mydesign);

System.out.println("AfterCompilation");

System.out.println(jasperReport.getColumnCount());

JasperPrint jp = JasperFillManager.fillReport(jasperReport,parameters,con);

System.out.println("After Filling the report");

JasperViewer.viewReport(jp,true);

 

Error is

Exception occurred during event dispatching:

java.lang.NullPointerException

at net.sf.jasperreports.engine.fill.JRFillTextElement$1.chop(JRFillTextElement.java:515)

at net.sf.jasperreports.engine.fill.JRFillStaticText.fill(JRFillStaticText.java:241)

at net.sf.jasperreports.engine.fill.JRFillBand.fillElements(JRFillBand.java:756)

at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:487)

at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:447)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageBand(JRVerticalFiller.java:1269)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:396)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:248)

at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:162)

at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:691)

at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:519)

at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:120)

at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:291)

at ReportQuery.runReport(ReportQuery.java:181)

at ReportQuery.fillgrid(ReportQuery.java:144)

at ReportQuery$1.actionPerformed(ReportQuery.java:83)

at javax.swing.JComboBox.fireActionEvent(JComboBox.java:882)

at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:906)

at javax.swing.JComboBox.contentsChanged(JComboBox.java:962)

at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:93)

at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:100)

at javax.swing.JComboBox.setSelectedItem(JComboBox.java:426)

at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:467)

at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:634)

at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:245)

at java.awt.Component.processMouseEvent(Component.java:3799)

at java.awt.Component.processEvent(Component.java:3628)

at java.awt.Container.processEvent(Container.java:1195)

at java.awt.Component.dispatchEventImpl(Component.java:2678)

at java.awt.Container.dispatchEventImpl(Container.java:1244)

at java.awt.Component.dispatchEvent(Component.java:2581)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2487)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2252)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2161)

at java.awt.Container.dispatchEventImpl(Container.java:1231)

at java.awt.Window.dispatchEventImpl(Window.java:964)

at java.awt.Component.dispatchEvent(Component.java:2581)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:434)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:172)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:131)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:126)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:118)

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...