Jasper Report questions.

0
package abc;
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.InputStream;import java.sql.*;
import net.sf.jasperreports.engine.*;import net.sf.jasperreports.engine.design.JasperDesign;import net.sf.jasperreports.engine.export.*;import net.sf.jasperreports.engine.xml.JRXmlLoader;import net.sf.jasperreports.view.JasperViewer;public class JasperReport {
public static void main(String[] args) {  // TODO Auto-generated method stub
  String url = "XXX";  String user = "XXX";  String pwd = "XXX";  try {   Connection connRead = DriverManager.getConnection(url, user, pwd);   String address = "C:\\JaspersoftWorkspace\\MyReports\\First.jrxml";   InputStream inputStream = new FileInputStream (address);   JasperDesign jasperDesign = JRXmlLoader.load(inputStream);   net.sf.jasperreports.engine.JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);   JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, connRead);   JasperExportManager.exportReportToPdfFile(jasperPrint, "c:/A/test_jasper.pdf");   JasperViewer.viewReport(jasperPrint);  } catch (SQLException | JRException | FileNotFoundException e) {   // TODO Auto-generated catch block   e.printStackTrace();  }   }
}
Exception in thread "main" java.lang.ClassCastException: [Lnet.sf.jasperreports.engine.type.CalculationEnum; cannot be cast to [Lnet.sf.jasperreports.engine.type.NamedEnum; at net.sf.jasperreports.engine.xml.XmlConstantPropertyRule.<init>(XmlConstantPropertyRule.java:47) at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.addDatasetRules(JRXmlDigesterFactory.java:1214) at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.configureDigester(JRXmlDigesterFactory.java:507) at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1438) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:262) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:247) at abc.JasperReport.main(JasperReport.java:28)

lzqweasz's picture
Joined: Nov 20 2014 - 6:20pm
Last seen: 5 years 2 months ago

5 Answers:

0
package abc;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.*;
 
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
public class JasperReport {
 
public static void main(String[] args) {
// TODO Auto-generated method stub
 
String url = "XXX";
String user = "XXX";
String pwd = "XXX";
try {
Connection connRead = DriverManager.getConnection(url, user, pwd);
String address = "C:\\JaspersoftWorkspace\\MyReports\\First.jrxml";
InputStream inputStream = new FileInputStream (address);
JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
net.sf.jasperreports.engine.JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, connRead);
JasperExportManager.exportReportToPdfFile(jasperPrint, "c:/A/test_jasper.pdf");
JasperViewer.viewReport(jasperPrint);
} catch (SQLException | JRException | FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}
 
}
 
lzqweasz's picture
Joined: Nov 20 2014 - 6:20pm
Last seen: 5 years 2 months ago
0

one more question

I can not run ireport 5.6.0 in win7. Should I set something?

lzqweasz's picture
Joined: Nov 20 2014 - 6:20pm
Last seen: 5 years 2 months ago
0

Yes, switch to Jaspersoft Studio. iReport is due to end of life next year. Shouldn't be using it now.

hozawa's picture
57871
Joined: Apr 24 2010 - 4:31pm
Last seen: 8 months 2 weeks ago
0

one more error, 

this morning I try to set the report data from HashMap, 

the error change to 

 

net.sf.jasperreports.engine.JRException: Error compiling report java source files : I:\Java SAP\SecondJasperreport\First_1416963786573_878040.java I:\Java SAP\SecondJasperreport\First_tableDataset_1416963786573_878040.java

 

I have no idea about those files.

 

Anyway, 

 

Exception in thread "main" java.lang.ClassCastException:[Lnet.sf.jasperreports.engine.type.CalculationEnum; cannot be cast to[Lnet.sf.jasperreports.engine.type.NamedEnum; at net.sf.jasperreports.engine.xml.XmlConstantPropertyRule.<init>(XmlConstantPropertyRule.java:47) at 

 

How can I fix those two question?

Please help.

Thanks.

lzqweasz's picture
Joined: Nov 20 2014 - 6:20pm
Last seen: 5 years 2 months ago
0

Finally, I export my first Jasper Report. 

I dont how to fix it.

The solutions is remove all the Jar and re-add.

 

Here is my environment(Only use Jasperreport).

Win 7

Eclipse IDE for Java and Report Developers
Version: Luna Release (4.4.0)
Build id: 20140612-0600
 
 
JAR List
jasperreports-5.6.1.jar
jasperreports-chart-themes-5.6.1.jar
jasperreports-fonts-5.6.1.jar
jasperreports-functions-5.6.1.jar
mysql-connector-java-5.1.9.jar
commons-digester-1.7.jar
commons-logging-1.1.jar
org.apache.commons.collections_3.2.0.v2013030210310.jar
joda-time-2.0.jar
commons-beanutils-1.8.3.jar
iTextAsian\iTextAsian.jar
jasper-compiler-jdt.jar
com.lowagie.text_2.1.7.v201004222200.jar
poi-3.5-FINAL.jar
iText-2.1.7.js2.jar
****Download from here : http://www.java2s.com/
 
lzqweasz's picture
Joined: Nov 20 2014 - 6:20pm
Last seen: 5 years 2 months ago
Feedback
randomness