我需要JasperReport的帮助,这是我的模板
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="HelloReportWorld">
<parameter name="reportTitle" class="java.lang.String"/>
<parameter name="author" class="java.lang.String"/>
<parameter name="startDate" class="java.lang.String"/>
<field name="CUSTOMER_ID" class="java.lang.Integer"/>
<field name="NAME" class="java.lang.String"/>
<field name="CITY" class="java.lang.String"/>
<field name="STATE" class="java.lang.String"/>
<title>
<band height="60">
<textField>
<reportElement x="0" y="10" width="500" height="40"/>
<textElement textAlignment="Center">
<font size="24"/>
</textElement>
<textFieldExpression class="java.lang.String">
<![CDATA[$P(reportTitle)]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="500" height="20"/>
<textElement textAlignment = "Center"/>
<textFieldExpression class="java.lang.String">
<![CDATA["Ejecutado por: " + $P(author) +
" on " + $P(startDate)]]>
</textFieldExpression>
</textField>
</band>
</title>
<columnHeader>
<band height="30">
<rectangle>
<reportElement x="0" y="0" width="500" height="25"/>
<graphicElement/>
</rectangle>
<staticText>
<reportElement x="5" y="5" width="50" height="15"/>
<textElement/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement x="55" y="5" width="250" height="15"/>
<text><![CDATA[Nombre]]></text>
</staticText>
<staticText>
<reportElement x="205" y="5" width="255" height="15"/>
<text><![CDATA[Ciudad, Estado]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="5" y="0" width="50" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$P(CUSTOMER_ID)]]></textFieldExpression>
</textField>
<textField>
<reportElement x="55" y="0" width="150" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P(NAME)]]></textFieldExpression>
</textField>
<textField>
<reportElement x="5" y="0" width="50" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P(CITY) + ", " + $P(STATE)]]></textFieldExpression>
</textField>
</band>
</detail>
这是主要课程:
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
/**
*
* @author alejandro
*/
public class JAsperDemo1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String reportSource = "./reports/templates/HolaMundo.jrxml";
String reportDest = "./reports/results/HolaMundo.html";
Map<String, Object> params = new HashMap<String, Object>();
params.put("reportTitle", "Informe Hola Mundo");
params.put("author", "Jose Javier Ber");
params.put("startDate",(new java.util.Date()).toString());
try
{
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
Class.forName("org.apache.derby.jdbc.ClientDriver");
java.sql.Connection conn = DriverManager.getConnection(
"jdbc:derby://localhost:1527/sample", "app", "app");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
}catch(JRException ex){
System.out.println(ex.getMessage());
}
}
}
这些是我得到的错误:
编译报表表达式类文件时遇到错误: C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:183: 错误:找不到符号 value = $ F(PRODUCT_ID); // $ JR_EXPR_ID = 8 $ ^符号:变量PRODUCT_ID位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:188: 错误:找不到符号 value = $ F(DESCRIPTION); // $ JR_EXPR_ID = 9 $ ^符号:变量描述位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:193: 错误:找不到符号 value = $ F(PURCHASE_COST); // $ JR_EXPR_ID = $ 10 ^符号:变量PURCHASE_COST位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:256: 错误:找不到符号 value = $ F(PRODUCT_ID); // $ JR_EXPR_ID = 8 $ ^符号:变量PRODUCT_ID位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:261: 错误:找不到符号 value = $ F(DESCRIPTION); // $ JR_EXPR_ID = 9 $ ^符号:变量描述位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:266: 错误:找不到符号 value = $ F(PURCHASE_COST); // $ JR_EXPR_ID = $ 10 ^符号:变量PURCHASE_COST位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:329: 错误:找不到符号 value = $ F(PRODUCT_ID); // $ JR_EXPR_ID = 8 $ ^符号:变量PRODUCT_ID位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:334: 错误:找不到符号 value = $ F(DESCRIPTION); // $ JR_EXPR_ID = 9 $ ^符号:变量描述位置:类HelloReportWorld_1460420530440_343732 C:\ Users \用户亚历\文件\的NetBeansProjects \ JasperDemo \ HelloReportWorld_1460420530440_343732.java:339: 错误:找不到符号 value = $ F(PURCHASE_COST); // $ JR_EXPR_ID = $ 10 ^符号:变量PURCHASE_COST位置:类HelloReportWorld_1460420530440_343732 9错误
答案 0 :(得分:0)
你必须把: 的 $ P {reportTitle} 强> 不 的 $ P(reportTitle)强>